Err, you’ve not understood me properly =/ I wasn’t saying your snippet was faulty, I was saying mine was. I know your code works, but it won’t work when applied to mine. The whole point of my code is for a crate to spawn when the user clicks. Your code just spawns the crate and allows it to be removed.
What I was saying was if I applied your remove code (which is almost identical to the one I already created) it clashes with the my spawnCrate function in terms of event handling (ended, moved, cancelled, began, etc.)
Here’s the code that spawns and removes the crate, for me, which is a bit buggy: local function spawnCrate(event)
local crate = display.newImage("images/crate.png")
crate.x = event.x; crate.y = event.y;
--crate.xScale = 0.5; crate.yScale = 0.5;
physics.addBody( crate, { density=15, friction=0.5, bounce=0.001} )
localGroup:insert(crate)
local function rmvCrate(event)
if event.phase == "moved" then
event.target:removeSelf()
end
end
crate:addEventListener("touch", rmvCrate)
end
Listener: background:addEventListener("tap", spawnCrate)
Thanks. [import]uid: 68047 topic_id: 11832 reply_id: 43171[/import]