Advertisement

Dummy Sprite Creation Logic

Started by April 15, 2002 10:30 AM
3 comments, last by edwinnie 22 years, 7 months ago
i have been using the Dummies book sample coded functions, and tried to generate a sprite from it. somehow i am missing some sort of link. Here is the problem> 1) settings > CRYSTAL_STATE_OFF 0 CRYSTAL_STATE_ON 1 BOB crystal; crystal.state = CRYSTAL_STATE_OFF (the initial sprite state is at OFF) 2) Init_Crystal() > this function resides in the game_init() section
          
void Init_Crystal(void)
{
// this function initializes and loads all the crystals 

int z = 0;
// load the crystal imagery 

Load_Bitmap_File(&bitmap8bit, "crystal1.bmp");

#if(CRYSTAL_STATE_ON)
{
// create the first bob

Create_BOB(&crystal,0,0,120,120,19,
            BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,
            DDSCAPS_SYSTEMMEMORY);

// load animation frames

for (int frame=0; frame < 19; frame++)
    Load_Frame_BOB(&crystal,&bitmap8bit,frame,frame%5,frame/5,BITMAP_EXTRACT_MODE_CELL);  

// load animation sequences

// ...blah blah


// set animation rate

Set_Anim_Speed_BOB(&crystal,1);
Set_Vel_BOB(&crystal, 0, 1000);
Set_Pos_BOB(&crystal, 270,0);

z = rand()%19;	
crystal.curr_frame = z;   

// set state to off

crystal.state = CRYSTAL_STATE_OFF;

// unload data infile

Unload_Bitmap_File(&bitmap8bit);
}
#endif// end Init_Crystal  

}  
  
3) Start_Crystal() > this function resides in the game_main() > a random frame number is generated for current frame(aniwae,i wonder if this is the missing link)
              
void Start_Crystal(void)
{
// this functions generates a crystal if state is on


if (crystal.state == CRYSTAL_STATE_OFF)
         { // turn crystal gen on

           crystal.state = CRYSTAL_STATE_ON;
       return;
        
    } // end if


} // end Start_Crystal  

  
4) Draw_Crystal() > this function in game_main() calls the Draw_BOB().
              
void Draw_Crystal(void)
{
//this function draws the crystal

if (crystal.state == CRYSTAL_STATE_ON)      
{
  Draw_BOB(&crystal,lpDDSBack);
}
}      
5)okie, the (supposed)logic is that Start_Crystal() will sent a message to Init_Crystal() & Draw_Crystal(), and an "object" is supposed to appear on the screen, which it didnt. [edited by - edwinnie on April 15, 2002 11:31:58 AM] [edited by - edwinnie on April 15, 2002 11:33:43 AM] [edited by - edwinnie on April 15, 2002 7:57:51 PM] [edited by - edwinnie on April 15, 2002 8:29:23 PM]
For the BOB engine, if I remember correctly, BOB_ATTR_MULTI_ANIM means that there is more than 1 animation sequence..

I didn''t see you load a sequence into the BOB, and you didn''t set the current sequence.

int animation[19] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }

Load_Animation_BOB( &crystal, 0, animation );
Set_Animation_BOB( &crystal, 0 );

I don''t know if those are the exact functions, but the idea should be clear.
I'm not the brightest something or other in a group or similar.~ me ~
Advertisement
well, actualli i did.

now that i have finally got a sprite to appear,
but i got another problem>

why does it flicker? and the color looks different?


Me again..
Color looks funny? I haven''t really used the 8-bit version of the ''engine/library''. It may be your palette. Make sure your setting it: (to the palette loaded w/ the 8-bit crystal graphic)

int Set_Palette( LPPALETTEENTRY set_palette );
^^^ palette function ^^^

Otherwise your using a default palette, setup in the DDraw_Init function... If this doesn''t work.. are you loading an 8-bit file? I guess you would be, because the file wouldn''t really load then.. but..

I don''t know about the flickering... It could be a few things:
.Your frames aren''t loading correctly
.Your animation sequence is wierd (hehe)
.Something your doing w/ visibility
.Animation speed

Frames not loading correctly could be a fencepost style error. Where your starting in the wrong place (1 cell to the right..?), and therefor loading a ''blank'' frame, instead of one that you wanted. I think the frame loading using cells starts at 0...


Saw that you were playing w/ the Anim speed. I''ve never played w/ this, but you can see what happens w/ you don''t use it.


~ me ~
I'm not the brightest something or other in a group or similar.~ me ~
ok color looks fine now coz i found out that Load_Frame_BOB()
was meant for 8 bit. i updated it by comparing updated functions
which were provided by the cd.

then, i realize...my background image was a biltted one.
it looks alright to me but if the "crystal" bitmap was on
top of it, this "crystal" bitmap flickers.

is it due to the background bitmap that was being blitted?

considering,
if the background image was biltted in game_init(), it will oso flicker.
but if it was biltted in game_main(), it will not flicker.

there is alt way to solve this.
use > Create_Bitmap()
Load_Bitmap_File()
Load_Image_Bitmap()
Unload_Image_Bitmap()

but Create_Bitmap() & Load_Image_Bitmap() r oso catered for 8bit only. i guess so because neither background image will appear
in game_init() nor game_main().
there are no updated functions for these.
its probably due to the memory allocation which i am not sure
how to go about it, and the memcpy() that needs editing.


  int Create_Bitmap(BITMAP_IMAGE_PTR image, int x, int y, int width, int height){// this function is used to intialize a bitmap// allocate the memoryif (!(image->buffer = (UCHAR *)malloc(width*height)))   return(0);// initialize variablesimage->state     = BITMAP_STATE_ALIVE;image->attr      = 0;image->width     = width;image->height    = height;image->x         = x;image->y         = y;image->num_bytes = width*height;// clear memory outmemset(image->buffer,0,width*height);// return successreturn(1);} // end Create_Bitmap  



  int Load_Image_Bitmap(BITMAP_IMAGE_PTR image, // bitmap image to load with data                      BITMAP_FILE_PTR bitmap,    // bitmap to scan image data from                      int cx,int cy,   // cell or absolute pos. to scan image from                      int mode)        // if 0 then cx,cy is cell position, else                                     // cx,cy are absolute coords{// this function extracts a bitmap out of a bitmap fileUCHAR *source_ptr,   // working pointers      *dest_ptr;// is this a valid bobif (!image)   return(0);// test the mode of extraction, cell based or absoluteif (mode==BITMAP_EXTRACT_MODE_CELL)   {   // re-compute x,y   cx = cx*(image->width+1) + 1;   cy = cy*(image->height+1) + 1;   } // end if// extract bitmap datasource_ptr = (UCHAR *)bitmap->buffer +      cy*bitmap->bitmapinfoheader.biWidth+cx;// assign a pointer to the bimap imagedest_ptr = (UCHAR *)image->buffer;// iterate thru each scanline and copy bitmapfor (int index_y=0; index_y<image->height; index_y++)    {    // copy next line of data to destination    memcpy(dest_ptr, source_ptr,image->width);    // advance pointers    dest_ptr   += image->width;    source_ptr += bitmap->bitmapinfoheader.biWidth;    } // end for index_y// set state to loadedimage->attr |= BITMAP_ATTR_LOADED;// return successreturn(1);} // end Load_Image_Bitmap  

This topic is closed to new replies.

Advertisement