making a sprite invisible

Hi,

I’m just trying to make a sprite re-appear on a random tile after collision with another sprite.  I can’t seem to get this working!  It seems simple enough but I’m not able to make this happen… is it possible that because I am in a collision that mte.update isn’t being called?

This is what I am doing:

local function onCollision( event )
        if ( event.phase == “began” ) then
            if event.object2.id == “hole” then
                    spinplayer()

function spinplayer()
    timer.performWithDelay(5, function() player.rotation = player.rotation + 10 end, 100)
    timer.performWithDelay(1000, relocateplayer(), 1)
    
end

function relocateplayer()
    tx =  math.floor(math.random() * 127.99)
    ty=  math.floor(math.random() * 127.99)
    print(“Relocating x”…tx…"  Y:"…ty)
–    player.isVisible = false
    mte.moveSpriteTo({sprite = player, locX =tx,locY= tx,time=1, onComplete = mte.setCameraFocus(player)  })
–    player.isVisible = true
end

It looks like I am stuck in a collision event…

 at the collision I do a mte.removeSprite(player, false)

but the physics engine still thinks a collision is going on… as the sprite is still in its location, just invisible…?

help

Hello gb8,

It’s possible that MTE is still processing the sprite’s previous move when you call mte.moveSpriteTo({sprite = player, locX =tx,locY= tx,time=1, onComplete = mte.setCameraFocus(player)  }). Try calling mte.cancelspriteMove(player) just before it.

function relocateplayer() tx = math.floor(math.random() \* 127.99) ty= math.floor(math.random() \* 127.99) print("Relocating x"..tx.." Y:"..ty) --player.isVisible = false mte.cancelSpriteMove(player) mte.moveSpriteTo({sprite = player, locX =tx,locY= tx,time=1, onComplete = mte.setCameraFocus(player)}) --player.isVisible = true end

That’s what it is dyson!

The move is trying to complete and the collision is trying to process!   Since I want the ship to hit the center of the black hole and then spin away into nothingness  I need the move to complete and then process the random jump. 

I’ll try setting a collision flag and then use the onComplete from the movesprite to do my jump.

Thanks, Greg

It looks like I am stuck in a collision event…

 at the collision I do a mte.removeSprite(player, false)

but the physics engine still thinks a collision is going on… as the sprite is still in its location, just invisible…?

help

Hello gb8,

It’s possible that MTE is still processing the sprite’s previous move when you call mte.moveSpriteTo({sprite = player, locX =tx,locY= tx,time=1, onComplete = mte.setCameraFocus(player)  }). Try calling mte.cancelspriteMove(player) just before it.

function relocateplayer() tx = math.floor(math.random() \* 127.99) ty= math.floor(math.random() \* 127.99) print("Relocating x"..tx.." Y:"..ty) --player.isVisible = false mte.cancelSpriteMove(player) mte.moveSpriteTo({sprite = player, locX =tx,locY= tx,time=1, onComplete = mte.setCameraFocus(player)}) --player.isVisible = true end

That’s what it is dyson!

The move is trying to complete and the collision is trying to process!   Since I want the ship to hit the center of the black hole and then spin away into nothingness  I need the move to complete and then process the random jump. 

I’ll try setting a collision flag and then use the onComplete from the movesprite to do my jump.

Thanks, Greg