Hello - I have some code here that when an image (which is my button) is clicked, a new image randomly appears. This is due to a table I created with some images inside.
local animalPic local button = display.newImageRect ("images/animalBtn.jpg", 200, 200) button.x = 250 button.y = 50 local myPics = {"images/animal1.png", "images/animal2.png"} function button:tap (event) local idx = math.random(#myPics) local img = myPics[idx] local animalPic = display.newImage(img) animalPic.x = contentCenterX animalPic.y = contentCenterY end button:addEventListener ("tap", button)
The problem with it is the graphics just keep piling up when I click the button. The correct behavior should be -
Button is clicked and an image is shown while removing the previous image. How do I incorporate this behavior? I already tried the removeSelf command and it doesnt work…Any help appreciated.