2D scrolling game

Started by
15 comments, last by Servant of the Lord 11 years, 1 month ago

I am gonna make a 2D scrolling game, kinda like Mario. What is the best way to move the screen? Move the player and update the camera accordingly or move the entire screen and let the player stay still?

Advertisement

Move the player, and then move the camera to the same position. Then when you draw, draw everything at an offset based on the camera's position.

I would go for a move the player and refresh camera position too, instead of moving the world. Otherwise:

  • it will be difficult to setup "effects" such as smooth camera following and so on...
  • it will be harder to accomplish scrolling since you'll have to update every object's position instead of just the player+camera
  • if you use a physics engine, it will be even harder to keep sprites and internal physics state in sync

I can't really think of an upside to moving the world instead...

As Willpowerd said, draw your objects at "absoluteObjectPosition - absoluteCameraPosition", and trim out objects not in view. absoluteCameraPosition = absolutePlayerPosition, most of the time. This is fairly simple and easy to implement, but works very well for most 2D situations.

I understand how to render objects relative to the camera. I'm not sure how I get the camera to follow the player, while keeping him centered.

I think you're going to need to explain what it is that you're not getting more precisely. Maybe if you start by explaining to us your process so far and then stop at the point where you're stuck and explain why you don't know what to do.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

I think you're going to need to explain what it is that you're not getting more precisely. Maybe if you start by explaining to us your process so far and then stop at the point where you're stuck and explain why you don't know what to do.

I wanna know how I can keep the player centered on the screen while moving him. I need the camera to "follow" the player so the camera's position is updated, but I dont know how I can accomplish this.

As state above

but you also need to center 0,0 to the middle of the screen in 2d so addhalf your screen dimension

camerapos = playerpos

for all objs

draw obj at objpos-camerapos+(screenDimension/2)

So instead of moving the player I should move the camera and just center the player in the camera?

You move the player normally then center the camera onto the player (camerapos = playerpos)

This topic is closed to new replies.

Advertisement