transitions and collisions, how to cancel a transition with a collision?

Hi,

I have a bullet which moves from the ship to the centre of the screen then destroys. this is done using a transition with an ‘onComplete’ command. I also have ships which move from the centre to the edges of the screen, then destroys. This is also set up using a transition and ‘onComplete’ command.

However, if a bullet hits a ship on the way, it destroys the ship and itself. I have this working fine, as long as I don’t have an ‘onComplete’ command in the transition.

if i have the ‘onComplete’ command in the bullet and ship transitions, the ‘onComplete’ command still tries to run, even though the object is destroyed. this causes a pause in the program.

I have copied my code below. Can anybody help?

[blockcode]function fire()

bullet = display.newCircle( ship.x, ship.y, 3 )
physics.addBody( bullet, redBody )
gamescreen:insert( 1, bullet )
bullet.collision = onCollision
laserchannel = audio.play( laser )
transition.to(bullet, { time = 500, x = centreX, y = centreY, width = 0.25, height = 0.25, onComplete = destroyBullet } )
bullet:addEventListener( “collision”, bullet )
end

function onCollision( self, event )
if ( event.phase == “began” ) then
event.target:removeSelf()
event.other:removeSelf()
bullet:removeEventListener( “collision”, bullet )
end
end

– Enemies –

function destroyShip(obj)
obj:removeSelf()
end

function spawnobst(event)

if dospawnE == 1 then

Enemylane = mRand(1,2)
enemyship = display.newImage(“shipafterburner.png”)
physics.addBody( enemyship, “static”, redBody )
gamescreen:insert( 1 , enemyship )
enemyship.alpha = 0.2
enemyship.xScale = 0.01
enemyship.yScale = 0.01
enemyship.x = centreX
enemyship.y = centreY
dospawnE = 0
if Enemylane == 1 then
enemyship.rotation = lane1rotation
transition.to( enemyship, { time=3000, xScale = 0.5, yScale = 0.5, x = lane1x, y = lane1y, transition=easing.inQuad, onComplete = destroyShip } )
[/blockcode]

[import]uid: 8699 topic_id: 5464 reply_id: 305464[/import]

I have found a workaround, which involves having an invisible wall to destroy the ship and bullets, rather than having the ‘onComplete’ command. [import]uid: 8699 topic_id: 5464 reply_id: 18397[/import]