Hi,
I have managed to get a bullet to destroy a ship and remove both objects. However, when the collision occurs it appears to cancel the transitions of other objects in the scene.
I have included the code for spawning a hoop, which grow before destroying itself, and, firing a bullet and destroying itself with the ship it collides with. But why would it effect the transitions of objects in other functions?
[blockcode] function spawnHoop(event)
if dospawn == 1 then
if speedlevel == 1 then
hoop = display.newImage(“circlegreen.png”)
gamescreen:insert( 1 , hoop )
dospawn = 0
hoop.alpha = 0.2
hoop.xScale = 0.01
hoop.yScale = 0.01
hoop.x = centreX
hoop.y = centreY
transition.to( hoop, { time=1000, alpha = 1,} )
transition.to( hoop, { time=1500, xScale = 1, yScale = 1, onComplete = destroyHoop } )
timer.performWithDelay(500, resetSpawn, 1 )
end
end
end[/blockcode]
[blockcode]function fire()
bullet = display.newCircle( ship.x, ship.y, 3 )
physics.addBody( bullet, “static”, redBody )
gamescreen:insert( 2, bullet )
bullet.collision = onLocalCollision
laserchannel = audio.play( laser )
transition.to(bullet, { time = 500, x = centreX, y = centreY, width = 0.25, height = 0.25, onComplete = destroyHoop } )
bullet:addEventListener( “collision”, bullet )
end
function onLocalCollision( self, event )
if ( event.phase == “began” ) then
event.target:removeSelf()
event.other:removeSelf()
bullet:removeEventListener(“collision”, bullet )
end
end[/blockcode]
Thanks
[import]uid: 8699 topic_id: 5451 reply_id: 305451[/import]
