Jump to content
  • Advertisement
Sign in to follow this  
Programmierer

Camera for 2-d side-scroller

This topic is 4120 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been reading "Beginning Game Programming" by Michael Morrison. He does not touch upon how to create a side-scroller where the camera flows with the character in the center. He only describes how to have a character reach the end of the screen and then "shift" to the next scene. Much like the way Zelda 3 (SNES) plays. Can anyone refer me to a resource where I can find out how to make the camera behave similar to a game like Mega Man for instance? (Where there is no shifting, just a smooth flow throughout the level) Thanks

Share this post


Link to post
Share on other sites
Advertisement
The general idea is that you store the position of the camera. You'd set that position to be above the player every frame. And you'd 'shift' all the drawing over and up by that amount.

If you need more help, maybe you should ask a more specific question.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kada2k6


Hey maybe you're aware and don't care of have decided for other reasons to do things that way, but that code seems like it has a lot of unnecessary multiplications and divisions that could be replaced by shifts and stored values... just a thought.

Share this post


Link to post
Share on other sites
just a generalization, the code is for you to figure out, in my oppinion.

by try thinking of it this way, was you see on the screen is determined by the camera, and the cameras position is determined by the player.


// real basic idea of the camera
class CCamera
{
private:

float m_map_x;
float m_map_y;
float m_width; // in tiles
float m_hieght; // in tiles

public:

// various functions for retrieving and changing data
};



now the game would use the cameras data to determined what parts of the map need to be displayed. but its up to you to figure out how you want the game or the players position to effect the cameras' position.

Share this post


Link to post
Share on other sites
Thanks Speedie and Kada, that's what I was looking for.

I'm guessing the length of a level would depend on how wide the bitmap is or something?

**To the above poster... I'm coding this in C++

Share this post


Link to post
Share on other sites
Quote:
Original post by Programmierer
Thanks Speedie and Kada, that's what I was looking for.

I'm guessing the length of a level would depend on how wide the bitmap is or something?

**To the above poster... I'm coding this in C++


are you using one bitmap(or image) for the entire bacground of your map? You should look into using tile maps. they're the most basic and most used way of storing and displaying map data.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!