One Button, Multiple touch events

I have 5 pictures on top of one another, I have one button, where I want it to remove one image every time the button is touched. I have no idea how to go about this. many thanks for any help.

Are these images inside a group?
Then you could just loop through the groupchildren :)

i.e.:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- Create Images
local imageA = display.newImage("ImageA.png")
-- etc
 
-- Create Group
local imageGroup = display.newGroup()
 
-- Insert Into Group (every image)
imageGroup:insert(imageA)
 
local function removeImage(event)
   -- using imageGroup.numChildren, we get the number of images inside the group and the last element
  -- we could also delete random images using math.random(1,imageGroup.numChildren)
   if (imageGroup.numChildren > 0) then
      imageGroup[imageGroup.numChildren]:removeSelf()
   end
end
 
Runtime:addEventListener("tap",removeImage)

Thank you very much!!! It is working perfectly!!!

is there a way to assign tap counts to different events?

like if I tap once it will remove an image
and if I tap again on the same button it was start an animation?

Thanks

I know am doing this code wrong, cause I am getting an error, any help?

1
2
3
4
5
6
7
8
9
10
11
local function removeImages( event )
        if event.phase == "ended" then
                layer6:removeSelf()
                later6 = nil
    end
        if layer6 == nil then
                layer5:removeSelf()
        end
end
 
shovel:addEventListener( "touch", removeImages )
views:1524 update:2011/11/25 8:45:21
corona forums © 2003-2011