Ending a collision event

Hi,

I’m trying to make a sprite jump to a random position after a collision with another object.

The problem I am having is that the collision event isn’t ended so I can’t move my sprite.  Is there any way to force a collision to be ‘ended’?  (I tried calling physics.removebody() but you can’t do that during a collision)

Thanks for any help, Greg

Well I removed my global listener, and setup a local listener.  This almost works… I’m getting recursive collisions but I think its a momentum issue.

physics.addBody( player, { density = 3.0, friction = 1.0, bounce = 0.3 } )
player.collision = onBlackHoleCollision
player:addEventListener( “collision”, player )

function onBlackHoleCollision(self, event)
    if event.phase==“began” then
            if event.other.id==“hole” then
                timer.performWithDelay(2, function() player.isBodyActive = false end, 1)
                timer.performWithDelay(3000, relocateplayer(), 1)
            end
    end        
    return true
end

Hi Greg,

All collisions should have an “ended” phase. When are you seeing this *not* occurring?

Brent

Hi Brent,

I’m using moveSpriteTo using dyson’s MTE… the destination is the center of the circle so MTE is making sure the sprite makes it.  At the same time, the collision detection is firing off trying to kill the timer but it can’t because the “ended” event can’t happen until MTE finishes.

dyson says to do a cancelMoveSprite on collision, but I want my player to end up in the middle of the blackhole before spinning into it.

Does that make any sense?

Thanks, Greg

Hi Greg,

I’m not familiar with MTE or its functionality. However, you may be able to “trick” the collision listener by dispatching an alternative event name to it after some point (i.e. the sprite reaches the center point). There’s quite a bit of potential for this using the “object:dispatchEvent()” function:

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Best regards,

Brent

Well I removed my global listener, and setup a local listener.  This almost works… I’m getting recursive collisions but I think its a momentum issue.

physics.addBody( player, { density = 3.0, friction = 1.0, bounce = 0.3 } )
player.collision = onBlackHoleCollision
player:addEventListener( “collision”, player )

function onBlackHoleCollision(self, event)
    if event.phase==“began” then
            if event.other.id==“hole” then
                timer.performWithDelay(2, function() player.isBodyActive = false end, 1)
                timer.performWithDelay(3000, relocateplayer(), 1)
            end
    end        
    return true
end

Hi Greg,

All collisions should have an “ended” phase. When are you seeing this *not* occurring?

Brent

Hi Brent,

I’m using moveSpriteTo using dyson’s MTE… the destination is the center of the circle so MTE is making sure the sprite makes it.  At the same time, the collision detection is firing off trying to kill the timer but it can’t because the “ended” event can’t happen until MTE finishes.

dyson says to do a cancelMoveSprite on collision, but I want my player to end up in the middle of the blackhole before spinning into it.

Does that make any sense?

Thanks, Greg

Hi Greg,

I’m not familiar with MTE or its functionality. However, you may be able to “trick” the collision listener by dispatching an alternative event name to it after some point (i.e. the sprite reaches the center point). There’s quite a bit of potential for this using the “object:dispatchEvent()” function:

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Best regards,

Brent