PDA

View Full Version : Scrolling backgrounds



MasterChafed
July 7th, 2006, 04:11
I need some help with making scrolling backgrounds. CAn someone point me to a tut or give me some advice. thx.

yaustar
July 7th, 2006, 12:23
Define scrolling backgrounds. Tiled or just plain images?

MasterChafed
July 7th, 2006, 12:33
just plain png's

MasterChafed
July 7th, 2006, 12:34
when you run to the edge of the screen i need the screen to scroll so you can continue moving in that direction.

yaustar
July 7th, 2006, 14:38
Do you want to continous scrolling (ie, player is 'still' on the screen the background scrolls) or staggered (ie, player hits the right edge of the screen, player is placed to the left and a new image is blitted to the background).

MasterChafed
July 7th, 2006, 22:36
I wanted it like Sora's adventure backgrounds. Where, when you get to a specific X coordinate on the screen the background scrolls, and when you get to the edge of the last picture, it stops scrolling

yaustar
July 8th, 2006, 00:04
The easiest way I found to do things like this is to set everything in World co-ordinates and have a camera object.

As every object's position is defined to the top left of the images, the camera's relative position to the screen will always be in the top left.

When you draw the screen, you draw everything that would be on screen relative to the camera based on their world co-ordinates.

So when you move your character, it is a certain distance from/to the camera, you move the camera to keep the player on screen.

I did this for my RTS Prototype that was 'released' a month or two back.

This is just one way to achieve the effect. The other is to have every object's position relative to the screen which I find harder to keep track of in my head and code.

MasterChafed
July 8th, 2006, 00:49
so, how would i go about making this "camera" object?

yaustar
July 8th, 2006, 01:04
All it is a x and y position.

eg.

camera x = 20
camera y = 30

sprite x = 40
sprite y = 50

to find out where to draw the sprite on the screen it is simply sprite - camera.

Therefore:
sprite on screen position x = 40 - 20 = 20
sprite on screen position y = 50 - 30 = 20

MasterChafed
July 8th, 2006, 01:57
oh, ic i wil try this later tonight

MasterChafed
July 8th, 2006, 01:58
thx a lot Yaustar