1
\$\begingroup\$

I was practicing the parkour tutorial for chapter 7, but I failed to understand why we should move the same delta movement of this.gameLayer, which contains the background layer and the animation layer in opposite direction. Why do we do this?

\$\endgroup\$
1
\$\begingroup\$

This is to keep the player centered on the screen (while maintaining the illusion of motion).

The player is moving (right) relative to this.gamelayer. If this.gamelayer is shifted to the left the same amount, the two movements will 'cancel' each other out.


The paragraphs right before these instructions explained in slightly different words:

Since the physic body will move right infinitely and the sprite will synchronize it's position with the physic body.

A few seconds later, the player will go outside of the screen, just as it is in the last tutorial.

So we need to move the game layer's x position each frame to make it in a visible range.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.