I searched the forum and couldn’t find a good example for this. I created a set number of objects (stars) on the screen. I want to remove each object individually when my character touch each one. If anyone can help me figure this one out I would really appreciate it. I’ve been able to create the stars/objects, however, I have not been able to remove (each one) when my character collide with them. here is a sample of my code. Just to be clear, what i am looking for is that once the stars are created, my character would collide with star1 and it would disappear, then collide with star2 and star2 would disappear and so on. Thanks again.
numOfImages = 20 -- define how many images on what on screen
local function displayNumber()
letterHolder = {} -- initialize array
for i=1,numOfImages do -- start for loop to go from 1 to 10
letterHolder[i]= display.newImageRect( "images/glow\_star.png", 20, 20 )
letterHolder[i].x = frog.x-- display the rectangle in a random x position on screen
letterHolder[i].y = frog.y-- display the rectangle in a random y position on screen
physics.addBody(letterHolder[i],"kinematic")
localGroup:insert(letterHolder[#letterHolder])
--letterHolder[i]: removeSelf()
--letterHolder[i]=nil
--letterHolder[#letterHolder].myName= "star"
local function onCollision(event)
if (event.phase == "ended") then
--print("collided")
print("collides")
--letterHolder[#letterHolder]:removeSelf()
letterHolder[i]:removeSelf()
end
end
--letterHolder[#letterHolder]:addEventListener("tap", onCollision)
girl:addEventListener("collision", onCollision)
end
end
timer.performWithDelay(600, displayNumber, numOfImages)
Error message: attempt to call method removeSelf a nil value. Not sure if this code would remove stars individually either. thanks again for the help. [import]uid: 104131 topic_id: 33807 reply_id: 333807[/import]