1 - Use a table listener not a global function.
2 - In general you’re not using the keyword local when you should. If you have to use a global to make your code work, then you’re not understanding and dealing with scope properly.
(I am assuming the above code is untested because of the typos: bullet vs bulet)
This is something like what you need:
local bullet = display.newImageRect("bullet",30,30) physic.adBody( bullet, "dynamic" ) bullet.gravityScale=0 bullet.isSensor=true bullet.x = enemy.x bullet.y = enemy.y bullet.x0 = bullet.x -- track original position of bullet bullet.y0 = bullet.y -- track original position of bullet function bullet.onComplete( self ) -- 'self' is bullet -- Extra saftey code. This will trigger if 'self' is no longer a valid object. if( self.removeSelf == nil ) then return end -- restore to original position self.x = self.x0 self.y = self.y0 -- Transition 'self' and pass self for 'onComplete' arg. -- Corona will detect that self (bullet) has a field 'onComplete' containing a reference to -- a function. transition.to( self, { time=2000, x = self.x - 400, delay = 4000, onComplete = self } ) end bullet:onComplete() -- Call onComplete manually to do first transistion. --As soon as bullet is removed via (display.remove() or obj:removeSelf) the transition is canceled.
Note: This is the ‘same’ example (more elaborate) that I gave previously. Don’t re-write it to be a global function and expect it to work. A global function will need to be written very differently and I won’t give an example because its a bad practice (for this usage).