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?
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 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.