hi all,

i'm trying to do a scroll effect on a bmp background for a game.
For example a bmp filled of stars that have to move from bottom to top.
I'm not using directX, only api.

I've tought to do it in this way, and that probaly is a wrong way:

DIB bitmap in memory

111111111
222222222
333333333

999999999

1)I copy firs line in a memory space created with GlobalAlloc.
2)I copy the second line onto first line of the bmp DIB.
3)I copy the third line onto second

Last) At the end i copy the first line that's in memory onto
the last of the DIB bitmap.

I'm sure that the game experts do it in a better way.

Could you teach me some technics ?

many thx Angelo
Posted on 2001-09-09 15:48:31 by Bit7
Hi !

It's not a fine solution you did. (I remember doing the same while programming my first stars on amiga. I had used the blitter because I didn't have thought of the sprite-abilities - very lame ;) !)

But here is what I would do (and this can be easily adapted to directdraw !)

If your screen has the size 640 * 480 then create a bitmap for your background with doubled size, means 640 * 960 (two screens upon). Then do the following steps:

1. Fill the entire background image with graphics, so that you can scroll 480 pixels down without redrawing anything ( it's like moving a frame along a wallpaper )

2. each time you have to blit the background onto your screen, blit the contents of the actual frame, whose size is equal to the screen (640 * 480)

3. after the blitting, move the coordinates of the frame 1 pixel down (or even more, due to your selected scroll-speed)

4. Fill the lines which are passed by with the new background-informations.

5. repeat steps 2,3, 4 until the frame has reached the bottom. After that you can position the frame at the top. the regions has already filled with new valid graphics-data by step 4 !


The advantage of this method is that no additional data-scrolling is used, only a few lines have to been redrawn if necessary. So it works for static backgrounds or those who displays large areas, which are build up of patterns !


Greetings, CALEB !
Posted on 2001-09-09 16:48:50 by Caleb
Angelo there is an example that comes with the masm package on how to scroll a bitmap. The bitmap is actually a double bitmap to make the scrolling look realistic. if your going to use the entire client area for the stars this method might not be right for you. A thread that sets and unsets pixels might be a better option.
Posted on 2001-09-09 16:49:28 by titan
Caleb,

thanks ! your is a great method. With this 'double bitmap' I can scroll the bitmap without any memory operation !
But it just need a double size bmp :( No problem for a 16colour bmp but for a 32bit per pixel size become big.


Titan,

i've unfortunately bought Tasm and i don't have masm examples. Could you pleas mail me the one you was talking about ?
I'm very curious.

angelo
Posted on 2001-09-10 01:03:11 by Bit7
Sorry angelo, i can't seem to find that example. I just looked all over the system. It may have been an example i got off the board and don't have anymore.
Maybe post a message requesting an example of a scrolling bit map

Here it what i use in a thread to scroll a bitmap:
Maybe it will help you get the idea.
_________________________________________________
ThreadProc PROC USES ebx Param:DWORD
LOCAL var2:DWORD,var1:DWORD:BMH:DWORD,BMW:DWORD

mov BMH,50
mov BMW,200

invoke LoadBitmap,hInstance,35 ;<BitMap ID
mov hBitmap,eax
invoke SelectObject,cdc,hBitmap
mov obitmap,eax

bla:

mov ebx,BMW ;<<BitMap width
mov var1, 0
.while var1 < ebx ;
invoke BitBlt,hdc,100,100,BMW,BMH,cdc,var1,0,SRCCOPY


invoke GetTickCount
mov var2, eax
add var2, 10 ; nominal milliseconds delay

.while eax < var2
invoke GetTickCount
.endw

add var1,2
.endw

jmp bla


ThreadProc ENDP

_______________________________________________


:alright:
Posted on 2001-09-10 10:22:17 by titan
titan,

thanks very much.
Your example is good and clear.
I've just two questions:
1)If you move your bmp leftward 2 lines per frame , you got to have a bmp large two times your window display wide, is it so ?
2)If i use Call Sleep,10 (just becouse is shorter to write) is the same of your GeTickCount or is slower ?

A
Posted on 2001-09-10 13:55:02 by Bit7
hey,
i've done my scroll ! :) :) It work very well !


Titan, i can probably answer now to my questions n.2: Sleep function stop the scrolling id i move the mouse :( , with GetTickCount it work fine :)

thanks all again
Posted on 2001-09-10 14:33:59 by Bit7