Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8991715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:47:33+00:00 2026-06-15T22:47:33+00:00

Very quick, and probably easy question… but its left me stumped for the last

  • 0

Very quick, and probably easy question… but its left me stumped for the last 30 minutes… But how can I remove items from the canvas/screen?

I know this works with removeSelf(), but I’m not quite sure how to use that in my example:

display.setStatusBar( display.HiddenStatusBar )

function cat1()
    displayCategory(1)

    print( "clicked 1" ) 
end

function cat2()
    displayCategory(2)

    print( "clicked 2" ) 
end

function cat3()
    displayCategory(3)

    print( "clicked 3" ) 
end

--category display
function displayCategory(cat)

    if (cat == nil) then
        cat = 1
    end

    print( cat )

    if (cat == 1) then
        local item1 = display.newRect(100,100,100,100)
        item1:setFillColor(255,255,0)
    elseif (cat == 2) then
        local item2 = display.newRect(200,100,100,100)
        item2:setFillColor(255,0,255)
    elseif (cat == 3) then
        local item3 = display.newRect(300,100,100,100)
        item3:setFillColor(0,255,255)
    end

end

--category buttons
local catBtn1 = display.newRect(0,0,50,50)
catBtn1:setFillColor( 255,0,0 )
catBtn1:addEventListener( "tap", cat1 )

local catBtn2 = display.newRect(60,0,50,50)
catBtn2:setFillColor( 0,255,0 )
catBtn2:addEventListener( "tap", cat2 )

local catBtn3 = display.newRect(120,0,50,50)
catBtn3:setFillColor( 0,0,255 )
catBtn3:addEventListener( "tap", cat3 )

Right now, every time I click on of my buttons, the corresponding item pops up, but doesnt disappear when I click on any of the other buttons. How would I go about that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:47:34+00:00Added an answer on June 15, 2026 at 10:47 pm

    First, create those itens on start, before the displayCategory function.
    Then you set them to not visible, like this:

    local item1 = display.newRect(100,100,100,100)
    item1:setFillColor(255,255,0)
    item1.isVisible = false
    

    Later you set the proper itens to visible or not as appropriate, in case of item 2 it would be

    item1.isVisible = false
    item2.isVisible = true
    item3.isVisible = false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is probably a very simple question, but I can't seem to
Very quick question: should I worry about RSS urls for search engine optimization? Can
This is probably a very quick fix, but I'm having trouble figuring out why
The question is probably worded in a very confusing way so here's a quick
This is a very quick (and probably noob) question. I am creating a dependencyobject
I asked this question earlier and I got very quick and helpful responses: Linq
quick and very basic newbie question. If i have list of dictionaries looking like
Quick question related to IIR filter coefficients. Here is a very typical implementation of
Very quick question for FreshBooks OAuth. When requesting a Request Token you need to
very quick question for you. When I store some automatic variable in C, asm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.