In my space shooter OmniBlaster, I use transition.to all the time for all my weapon fire (since its all going in a straight line).
[lua]local function removeCenterPhasers(t)
if phaserCenter ~= nil then
if phaserCenterTween ~= nil then
transition.cancel(phaserCenterTween)
phaserCenterTween = nil
end
phaserCenter:removeSelf()
phaserCenter = nil
end
end
…
phaserCenter = display.newImageRect(blastImg, 9, 32)
phaserCenter.x = myRocket.x + 32
phaserCenter.y = myRocket.y + 0
phaserCenterTween = transition.to(phaserCenter, { y = -32, time=500, onComplete=removeCenterPhasers})[/lua]
So when I create the transition.to, I store a reference to the transition into “phaserCenterTween” and when it ends up off screen (y = -32) I then remove that object and its tween from memory.
Now during my game play loop (eventListener on EnterFrame) I have code that detects if my blaster image object has collided with my table of targets:
[lua] if phaserCenter then
if hasCollided(bullets[i], phaserCenter) then
removeCenterPhasers(bullets[i])
end
end[/lua]
of course I’ve removed some other game play code to get this down to what you need. But the idea is to let the transition.to move your image. When it completes, use the call back function to clear the tween and clear the image. Then if it runs into something, get rid of it too. [import]uid: 19626 topic_id: 12160 reply_id: 44429[/import]