Skip to main content
GameDev.net gamedev.net
🔒 Locked

Moving screen

Started by Lesan Dec 21, 2006 at 8:41 AM 7 replies 2.4k views
Bimble Bob
Bimble Bob
Is it 2D? I'm assuming it is. In that case is the map tile based? If it is you have a "Tile Buffer" which stores information on the tiles that aren't currently on screen. If the player moves then you re-draw the map on screen with the tile information stored in the buffer. Sorry if that's a bit vague or doesn't make sense :S
It's not a bug... it's a feature!
Sc4Freak
Sc4Freak
In 2D, the classic way is to move everything relative to the camera. That is, camera is in one position and the entire world moves about to simulate a moving camera.
BeerNutts
BeerNutts
You'll get whistled for having a moving screen. It's illegal...in basketball.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
GPxz
GPxz
You forgot to say if its tile-based or not,

If its not, you should subtract the object X and Y position by CamX and CamY

CamX and CamY refer to the camera position

Example:

for(int i=0;idraw_sprite(screen, object.bmp, X-CamX, Y-CamY);


You may make a If to check if the X-CamX/Y-CamY is inside the screen, to avoid spending process time with unecessary draw sprites. I dont know about others, but in Allegro, theres no problem giving negative values or values bigger than screen,. So, the code above is valid
My MSN: gerunbaum@hotmail.com
iliak
iliak
Here ?
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
rasher_b2
rasher_b2
If you make a camera you can use it to only display what's on screen and to determine where an entity/tile (I'll refer to them as objects) lies in relation to the screen.

For example, let's say you have an object location at x=100,y=0 in your world. If the camera (viewable area) is at x=50,y=0 and we have checked that our object intersects the camera (it is on screen) then we can use the camera's coordinates to work out where to draw the object on screen. We do this by subtracting the camera's coordinates from the objects (x:100 - 50 = 50, y:0 - 0 = 0) so we know that we need to draw the object at the coordinates 50,0 on the screen.

Using a method like this means that each object moves around in relation to the game world but is drawn in relation to the screen (the location of the camera).

I'm not sure how much sense that makes but I hope it helps.
Lesan
Lesan
Quote:
Original post by rasher_b2
If you make a camera you can use it to only display what's on screen and to determine where an entity/tile (I'll refer to them as objects) lies in relation to the screen.

For example, let's say you have an object location at x=100,y=0 in your world. If the camera (viewable area) is at x=50,y=0 and we have checked that our object intersects the camera (it is on screen) then we can use the camera's coordinates to work out where to draw the object on screen. We do this by subtracting the camera's coordinates from the objects (x:100 - 50 = 50, y:0 - 0 = 0) so we know that we need to draw the object at the coordinates 50,0 on the screen.

Using a method like this means that each object moves around in relation to the game world but is drawn in relation to the screen (the location of the camera).

I'm not sure how much sense that makes but I hope it helps.


It helped. Now I'm sure I have an idea.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.