Skip to main content
gamedev.net
🔒 Locked

Scrolling Engine

Started by PsYchOtroW Sep 26, 2000 at 2:49 PM 6 replies 600+ views
Original Post
PsYchOtroW
PsYchOtroW
Hi Everybody, i am using the Engine from "Tricks and Tips of the Windows Game Programming Gurus". How i can Draw an Bitmap with 1000x600 and scroll the bitmap. On page 490 is an picture of this but i don`t know how i can make it. Thanks Lutz Hören
psYchOtroW
Ratman
Ratman
Im kinda wondering the same thing, but what Ive been doing is keep an X and Y (or whatever you need) offset variables, and when they scroll the screen increment them or decrease them.

So you might be like DrawImage(Background, -230, 0) which would leave out the first 230 pixels of each line.

I dont think this will effect speed because you still only drawing 640x480 (or whatever res your using) pixels on the screen at once.
BitBlt
BitBlt
First off you have to make sure you have a clipper set up. Then just change the upper left corner coords according to keypresses, like this:

RECT bitmap_dest;
bitmap_dest.top = 0; // begin by drawing bitmap at (0,0)
bitmap_dest.left = 0;
bitmap_dest.right = 1000; // This will be clipped
bitmap_dest.bottom = 600; // so will this
...
...
if (/*right keypress*/)
{
bitmap_dest.left += 10; // scroll bitmap 10 pixels to the right
if (bitmap_dest.left>(1000-640) // Boundary checking (not complete)
{
bitmap_dest.left=(1000-640);
}
}
// Go on and check for all keypresses
...
// then
lpDDSback->Blt(bitmap_dest, // use our coords for destination
lpDDSbmp, // bitmap that 1000x600 image is on
NULL, // use entire surface for source
DDBLT_WAIT); // Blt flags

This is a very loose example, no error checking and not extremely thorough, but you get the idea. Try it out.





"We are the music makers, and the dreamers of the dreams."
- Willy Wonka

Edited by - BitBlt on September 26, 2000 4:29:36 PM
BitBlt
BitBlt
Just had another idea, maybe better. Keep a RECT that is the source that you want blted to the screen. Here''s another example:

RECT bitmap_src;
bitmap_src.top = 0; // This time begin by drawing (0,0)-(640,480)
bitmap_src.left = 0;
bitmap_src.right = 640;
bitmap_src.bottom = 480;
...
...
if (/*right keypress*/)
{
bitmap_src.left += 10; // scroll right 10 pixels
bitmap_src.right += 10; // remember, you don''t want an incomplete screen

if (bitmap_src.right>1000)
{
bitmap_src.right=1000;
bitmap_src.left=1000-640;
}
}
// check for other keypresses
lpDDSback->Blt(NULL, // use entire destination surface lpDDSbmp, // bitmap that 1000x600 image is on bitmap_src, // use our coords for source DDBLT_WAIT); // Blt flags

Again, kinda incomplete. This may be faster since it''s not drawing parts of the screen that won''t be seen.





"We are the music makers, and the dreamers of the dreams."
- Willy Wonka
PsYchOtroW
PsYchOtroW
Ok,
but how i can draw the bitmap. On the Back Buffer?
psYchOtroW
PsYchOtroW
PsYchOtroW
What is the lpDDSbmp. I am using the Engine from TOTWGPG... How i can implement this...?
psYchOtroW
BitBlt
BitBlt
My mistake for not clarifying, lpDDSbmp is the surface that contains the bitmap that you''re trying to blt. If you''re using the game engine from TOTWGPG, I guess it''s the GPdumb library, I don''t have the book. I think there''s a function called DD_Create_Surface(). Try this:

LPDIRECTDRAWSURFACE lpDDSbmp; // call it whatever you want
lpDDSbmp = DD_Create_Surface(1000, 600, 0);

I have WGPFD, and that''s what he does to create a surface. There maybe a function to draw the bitmap for you, like Draw_Bitmap(int x, int y) or something. Then just change it accordingly. Oh yeh, the call to Blt is what draws the bitmap onto the backbuffer. lpDDSback is your backbuffer in those examples. If things are still a little unclear, let me know and I''ll try to help.
Fourth Horseman
Fourth Horseman
Hi, just thought I''d join in here. That was the basic theory behind my scrolling engine too, but what happened is that if you held it down for a min straight it would keep scrolling through but then it would start to lag hell. Also, for no apparent reason the screen would start scrolling down too ! just so you can see and maybe help me, this is the code (only for scrolling to the right so far):


--------------- START CODE HERE ---------------
    


int Game_Main(void *parms)
{



// this is the workhorse of your game it will be called

// continuously in real-time this is like main() in C
// all the calls for you game go here!


int index; // looping var


// start the timing clock

Start_Clock();

// clear the drawing surface

DD_Fill_Surface(lpddsback, 0);

// lock back buffer and copy background into it

DD_Lock_Back_Surface();

// draw background

Draw_Bitmap(&background_bmp, back_buffer, back_lpitch,0);

// unlock back surface

DD_Unlock_Back_Surface();

// read keyboard

DI_Read_Keyboard();

// animate the man

Animate_BOB(&man);

// let player move the man

// allow player to move

if (keyboard_state[DIK_RIGHT])
man.x+=12;
else
if (keyboard_state[DIK_LEFT])
man.x-=12;

if (keyboard_state[DIK_UP])
man.y-=12;
else
if (keyboard_state[DIK_DOWN])
man.y+=12;

int chk_mveloop = 0;

// test if man is close to positive x edge

if (man.x >= (SCREEN_WIDTH - (SCREEN_WIDTH/8))) {
xBackCoord += (SCREEN_WIDTH - (SCREEN_WIDTH/8));
yBackCoord = 0;
man.x = (SCREEN_WIDTH - (SCREEN_WIDTH/8));
chk_mveloop++;
}
// load background image

if (chk_mveloop = 2) {
Load_Bitmap_File(&bitmap8bit, "DUNGEON2.BMP");
Create_Bitmap(&background_bmp,xBackCoord,yBackCoord,640,480);
Load_Image_Bitmap(&background_bmp, &bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);

};

// draw the man

Draw_BOB(&man, lpddsback);

// draw title

Draw_Text_GDI("I guess i''m glad this works now.",10, 10,RGB(0,255,255), lpddsback);

// flip the surfaces

DD_Flip();

// sync to 30ish fps

Wait_Clock(30);

// check of user is trying to exit

if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE])
{
PostMessage(main_window_handle, WM_DESTROY,0,0);

// stop all sounds

Stop_All_Sounds();

// do a screen transition

Screen_Transitions(SCREEN_DARKNESS,NULL,0);

} // end if


// return success

return(1);

} // end Game_Main




--------------- FINISHCODE HERE ---------------

Does it have to do with fps or what ??


Sincerely,
Jonathan
A.K.A. -- Fourth Horseman
Sincerely,JonathanA.K.A. -- Fourth Horseman

Topic Locked

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

Sign in to reply to this topic.