Side scroll camera or follow?

Side scroll camera or follow?
0.0 0

#1

Hi,

I’m new to building games.

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.

Thanks,

Tim


#2

It depends on what kind of camera scroll you want.

The very basic one - just move layers on scene.


#3

To be honest, I want to do something like this: http://www.badlogicgames.com/wordpress/?p=2017

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.


#4

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:

  1. Store player position of the previous frame
  2. Get current player position
  3. Has the player moved? (if x positions are different - he has)
  4. Figure out by how much has he moved?
  5. Now moving player right is essentially the same as moving the world left (that whole theory of relativity)
  6. So as your player moves - you move the world in the opposite direction

Does this approach make sense?


#5

Thanks BeZe. I will come back on this later when I have a bit more time. Great advice though :slight_smile: