How do i keep the screen on the player?

Started by
1 comment, last by DevLiquidKnight 21 years, 8 months ago
I have varibles set up for the top left hand corner of the screen and im trying to figure out how to make the screen stay centered on the player if the screen goes left to right it goes at the speed of 3 pixles per frame and the player moves at 1 pixle per frame. Ive had a few problems where the screen isnt centered correctly. How could i fix this?
Advertisement
Why should you move the screen faster than the player? Just move them at the same rate. Or calculate the screen position directly based on the player position. Typically to centre something you need to subtract half the width or whatever. So to centre a 640x480 screen on a player, you set the top-left of the screen to -320, -240 compared to the player.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
screenx = playerx - ScreenResolutionX/2
screeny = playery - ScreenResolutionY/2

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Dot Com | GameShot ]

This topic is closed to new replies.

Advertisement