scrolling

If I have a small setup where I can scroll the background tiles around, how do I set it up so that my objects scroll with the background instead of staying on the screen all the time? Can some explain the theory behind this not the details.

This gets very tricky very quickly. To make it easier let’s assume:

1> your map takes up the enitire display
2> your objects aren’t moving inside of the map
3> the map is initially displayed showing the upper left hand corner in the upper left hand corner of the screen
4> your screen coordinate system starts at 0,0 on the screen in the upper left hand corner and X increases to the right, Y increases down

Object (A) is at coordinates 100,100 inside of the map. Now you want to scroll the map horizontally toward the left side of the screen by 2 pixels. Now the map is really at -2,0 in screen coordinates.

(A) needs to move the same amount so you could simply decrement (A)'s X value by two but this isn’t really what you want since you want (A) coordinate system to be relative to the map not the screen.

Instead of changing (A)'s X value you need to make sure a draws itself at 100+mapXOffset,100. Where mapXOffset is -2 because you moved the map to the left by two pixels.

Basically the trick is to have two coordinate systems, one for the screen and one for the map. Draw the map in screen coords and the objects in the map in map coords. This starts to get really hairy when the map and the objects inside of it can move at the same time.

Wow, thanx for the quick r reply, very helpfull 8)