Can anyone help me to understand how to scroll my current layer to follow the player. My player is a box2d controlled sprite and I want to be able to move my layer towards the player from right to left and also have the player respond to physics.
Should I be looking at using cc.Camera (which seems undefined in javascript) or the cc.Follow action.
So far I have the physics, have created the blocks and the player and have the code for key presses but then I got stuck. If you fancy some more beer money to finish it off let me know.
Oh, that’s an easy one. Let’s work through this. I’ll explain how I see it and you can try it. If after this you get stuck - we’ll work things out.
So, based on your video, you want to move the camera in horizontal space. That is a bit different than bidirectional. Also, you want it to be glued to your player object, and not worry about being within a boundary box of a player.
So here’s an approach I would take:
Store player position of the previous frame
Get current player position
Has the player moved? (if x positions are different - he has)
Figure out by how much has he moved?
Now moving player right is essentially the same as moving the world left (that whole theory of relativity)
So as your player moves - you move the world in the opposite direction