what's the system behind scrolling? thanks.

nop
Posted on 2001-12-27 13:00:38 by NOP-erator
if you're talking about; how to scroll the bigger image on the smaller screen, then here's the example:


You can scroll it manually (your own alg.) on the back surface (if using dx), and then swap bufers.





---------------------------------------------------
The only way to achieve the goal is fight.
---------------------------------------------------
Posted on 2001-12-29 20:49:33 by ti_mo_n
For example, let's say you have a character in a 2D field. You use the position (x,y) of the character to find the portion of the field you have to display. Then you scan your list of elements and you display those whose coordinates are in the portion. When the player moves, you update the coordinates (x,y) of the character. It will define a new portion and new elements to be displayed.
Posted on 2001-12-30 06:55:03 by Dr. Manhattan
Lets say we havea RTS with a map of 256x256 tiles, each tile is 32x32 pixels. The whole image will be 8192x8192 pixels...much too big

So lets say we also have a screen of 800x600 pixels that is about:
25x18 tiles.

Let's define x_screen,y_screen two variables to hold curent screen start

when the game starts we are at top left so x_screen=0,y_screen=0

Each frame we render the background by getting tiles from x_screen,y_screen up to x_screen+25, y_screen+19

when the user scrolls right (ie he moves mouse on right edge) we increment x_screen by 1, if he scrolls left we decrement ... same by Y. Then we render the image starting from the new x_screen,y_screen allways with the same width (25,19)

Now for a optimised faster scrolling:

Its easy to see you do not have to do the render every frame, you can do it only when the user makes scroll. But you will have to render at first frame :)

Also you do not have to render the whole image on a scroll, you can use the old image, move it by one tile size in the oposite direction of scroll (using a fast blit) and then render only the required row/column of tiles.

One more variation is smooth scrolling, or pixel by pixel scrolling.

You can have a border arround the screen lets say 4 tiles each side, and only scroll a pixel at a time, you will still do 32pixels render when required...but that will be done on the border that is not visible... et voila you simulate a pixel by pixel scroll....
of course you will have to accelerate to 32pixel at atime again if the user insists keeping the mouse on the right side of the screen... or the scroll will be/feel much too slow ...

So this is accelerated scrolling....

this kind of scrolling from above is used in RTS's, but in RPG's the screen scrolls as the main character moves, so he is always in the center of the screen ... so here you will render form x_screen-screen_dx/2 up to x_screen+screen_dx/2 on X and same relations on Y... take care at the margins of the universe...character may faaaaaallll......
Posted on 2001-12-30 07:11:12 by BogdanOntanu
thank you all. that helped me very much!

nop
Posted on 2001-12-30 07:24:03 by NOP-erator