Need help with moveBy logic and object's position.

Hi,

In my game I have a player object and if the player hits an “obstacle”, they get a transition.moveBy applied to them which moves them to the left like so:

transition.moveBy(thisPlayer, { x = -moveAmount, y = 0, time = moveXby.moveByTime })

I am trying to figure out what the best way is to check if they reached the left edge of the screen while the transition is being applied to them.

I have a function I call when a collision is registered which checks the player’s position like so:

local function playerReachedLeftEdge(player) if ((player.x - (player.contentWidth/2)) \<= display.screenOriginX) then -- apply transition to move player left return true else -- cancel all transitions on this player return false end end

3 scenarios can happen here:

  1. The player is nowhere near the left edge of the screen, moveby is fine
  2. The player is on the left edge of the screen therefore no moveby is called
  3. In the process of transitioning, they reach the left edge of the screen

How do I check for if the player reached the edge of the screen while the transition is being applied to them? I know I can use onStart to call a function but what logic do I put in the function?

Thanks in advance!

Ps. Also, what is the difference between transition.moveBy() and transition.to()?

I would use an enterFrame listener to check the position each frame and then take any necessary action.

function player.enterFrame( self ) if( self.x = ??? ) do something ... end Runtime:addEventListener( "enterFrame", player )

 

I never use moveBy, but I think the big difference is:

  • transition.to() - Sets the named fields to a value over time.
  • transition.moveBy() - Seems to add a delta to an objects position over time.

You can probably work this out by writing some small tests and comparing the results.

Right, transition.to() is like “moveTo” instead of moveBy, makes sense. Ya, I ended up using an enterFrame listener and it got the job done.

Cheers!

I would use an enterFrame listener to check the position each frame and then take any necessary action.

function player.enterFrame( self ) if( self.x = ??? ) do something ... end Runtime:addEventListener( "enterFrame", player )

 

I never use moveBy, but I think the big difference is:

  • transition.to() - Sets the named fields to a value over time.
  • transition.moveBy() - Seems to add a delta to an objects position over time.

You can probably work this out by writing some small tests and comparing the results.

Right, transition.to() is like “moveTo” instead of moveBy, makes sense. Ya, I ended up using an enterFrame listener and it got the job done.

Cheers!