I have a function where when you press a button an image is displayed. I would like to, when the user presses the button again, to remove the image, then display it again, so a bunch of them dont pile up.
I could only get it working so far with a global, and calling display.remove at the start of the function. How could I use a local to do this?
–
local function animate( event )
display.remove( image )
local physics = require( “physics” )
physics.start()
local ground = display.newImage( “ground.png”, 75, 200 )
physics.addBody( ground, “static”, { friction=0.5, bounce=0.3 } )
image = display.newImageRect( “1.png”, 90, 100 )
image.x = 100
image.y = -85
physics.addBody( image, { density=3.0, friction=0.5, bounce=0.3 } )
end
–