delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/01/06:34:50

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem....
Date: Sun, 1 Feb 1998 10:08:05 +0000
Organization: None
Distribution: world
Message-ID: <2B5e0BAFmE10EwH2@talula.demon.co.uk>
References: <MPG DOT f3d7b1abfd86ac6989684 AT news DOT rmci DOT net>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 54
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Tim Elliott writes:
>double_buffer = create_bitmap(320,200);
>clear(double_buffer);

Little point: there is no need to bother clearing this here, since you
are going to do the same thing later in your main game loop.

>background = create_bitmap(320,200);
>background = (BITMAP *) bp_data[BG].dat;

Another little point: that create_bitmap() call is redundant, since you
are just going to discard the object that it returns by assigning a
different value to the background pointer in the next line. You only
need to create the object yourself if you aren't getting it from any
other place, like from inside a datafile...

>for (index=0; index<5; index++)
>       hero[index] = create_bitmap(25,35);
>
>hero[0] = (BITMAP *) bp_data[RS_HERO].dat;
>hero[1] = (BITMAP *) bp_data[HR_1].dat;
>hero[2] = (BITMAP *) bp_data[HR_2].dat;
>hero[3] = (BITMAP *) bp_data[HR_3].dat;
>hero[4] = (BITMAP *) bp_data[HR_4].dat;

Same thing here: get rid of those create_bitmap() calls.

>do{
>
>       hy--;
>       hframe++;
>      change = 1;
[...]
>       clear( double_buffer);
>       blit( background, double_buffer,0,0,0,0,320,200);

That clear is redundant. Since you cover the entire bitmap with a solid
blit in the very next line, it doesn't matter what the previous contents
might be, so clearing it first is just a waste of time.

>       draw_sprite(double_buffer,hero[hframe],hx,hy);
>       blit(double_buffer,screen,0,0,0,0,320,200);
>}while ( !key[KEY_ESC] );      

And finally here is the problem. You are using hframe as an index into
your array of animation frames, and incrementing this every time round
the loop, but there are only five frames so what is going to happen on
the sixth time around? Try using hframe%5, or resetting your counter to
zero whenever it gets too big...


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019