Jump to content
  • Advertisement
Sign in to follow this  
Toshi Brown

"Camera" movement in C++ with Allegro 5

This topic is 2154 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

Hey guys,


A second question in one morning.. something that has been bugging me.


I have been following the great guide by Mike Geig at fixbyproximity.com, and have made a background for my character to walk on.


However, I want the "background" or map to be much larger than one screen worth, and so have designed a tile background.


The problem is, that the "camera" or viewpoint of the player, doesnt move.


So, the players character can move off screen, ostensibly on to the different areas of the mapped background, but can no longer be seen by the player.


Alternatively, the mapped background is much bigger than what is seen on the screen, but the only way to see it is by including an "offset x and y" which moves the background itself, but then the players character is not connected to the background, it is as if the ground is moving out from underneath him but he stays in the same place.


If I were to leave the background not being able to move, have the character only bound by the maximum background size instead of WIDTH + HEIGHT (of the display), but have the players viewpoint/camera actually move instead around the background, tied to the players character, this would be a solution I would be very happy with.


Is this possible, and if so, how would I make it happen?




Share this post

Link to post
Share on other sites
Use two coordinate systems. The first should be used for the background, the player, and all the game logic.

The second coordinate system is for rendering and represents the screen.

Whenever you render something you will need to transform from world coordinates to screen coordinates. This will probably just be a case of adding an offset.

You can use a viewpoint or camera object to handle the transformations. Then moving the camera will change the visible area on the screen.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!