This topic is now archived and is closed to further replies.


Blitting the sprite to the the screen... ugh - HELP!

Recommended Posts

I''m trying to make a class that''s a 2d sprite that can be blitted on to the screen using Direct Draw''s blt function... Here''s the Declaration of the class...
class Sprite


	int x;		// x pos

	int y;		// y pos

	int xv;		// x velocity

	int yv;		// y velocity

	int width;	//width

	int height;	//height

	//Function Declarations

	Sprite(int xx, int yy, int wwidth, int hheight, int mode); // mode - set to DDSCAPS_VIDEOMEMORY or DDSCAPS_SYSTEMMEMORY

	Sprite& Sprite::operator=(Sprite spritecopy);
    HRESULT Load_Sprite_Bitmap(char* bmpName);          
	//HRESULT Draw_Scaled_Sprite(Sprite sprite, int swidth, int sheight,LPDIRECTDRAWSURFACE7 dest);

	HRESULT Load_Frame_Sprite(int cx, int cy);                   // cx,cy are absolute coords

	HRESULT Animate_Sprite();
	HRESULT Move_Sprite();
	HRESULT Load_Animation_Sprite(int anim_index, int num_frames, int *sequence);
	//HRESULT Set_Anim_Speed_Sprite(Sprite sprite,int speed);

	HRESULT Set_Animation_Sprite(int anim_index);
	//HRESULT Hide_Sprite(Sprite sprite);

	//HRESULT Show_Sprite(Sprite sprite);

	//bool Collision_Sprites(Sprite sprite1, Sprite sprite2);


    int curr_frame;     // current animation frame

    int num_frames;     // total number of animation frames

    int curr_animation; // index of current animation

    int anim_counter;   // used to time animation transitions

    int anim_index;     // animation element index

    int anim_count_max; // number of cycles before animation

    int *animations[NUM_SPRITE_FRAMES]; // animation sequences

	DDBLTFX s_ddbltfx;
	DDCOLORKEY color_key;
	RECT images[NUM_SPRITE_FRAMES];	//hold the blit info (the frames)

Now here are the two functions that are very simple but don''t seem to work... Assuming that the lpddssprite surface has a bitmap already loaded to it I use these two member functions.
	s_ddbltfx.dwSize = sizeof(DDBLTFX);
	s_ddbltfx.ddckSrcColorkey = color_key;

	RECT destrect;

	destrect.left = x; = y;
	destrect.right = width + x;
	destrect.bottom = height + y;

	dest->Blt(&(images[curr_frame]),lpddssprite, &destrect, (DDBLT_KEYSRC | DDBLT_WAIT), &s_ddbltfx);

    return g_ddrval;

HRESULT Sprite::Load_Frame_Sprite(int cx, int cy)
	cx = cx * (width + 1) + 1; 
	cy = cy * (height + 1) + 1;

	RECT temprect; = cy;
	temprect.left = cx;
	temprect.bottom = cy + height; // - 1 ?

	temprect.right = cx + width; // - 1 ?

	images[curr_frame] = temprect;
	return g_ddrval;
First I would load the frame then call Draw_Sprite... It has no compile errors - no windows errors... It just doesn''t show anything... I wouldn''t really care if it even showed up garble... but no - it had to show NOTHING!!! Any ideas, Thanks, Destroyer

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
I don''t know very much DirectX (nor English so excuse me)
Try to put some breakpoints to see if u have correctly loaded the sprite.
If it''s good, perhaps you''re sprite is not TOTALLY in the screen.
_________ _________ __________
| | _ | __ | |_ |
| | |_| | |__| | |__| |
|_____ | |________| |_________|
The screen The sprite The sprite The sprite doesn''t
appear on appear on the
the screen screen

or perhaps u don''t have correctly initialised you''re curr_frame or you''re destRect

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
oups !!!
the littles schemes aren''t in the good order, try to understand if u can...
I try to do them again
| |
| |
|________| the screen
|_| the sprite
| _ |
| |_| |
|________| here, it works
| |
|_| |
|________| here the sprite doesn''t appear (in DD7)

that''s all folk !


Share this post

Link to post
Share on other sites
Guest Anonymous Poster
problems with spaces !!!



Share this post

Link to post
Share on other sites
Try setting the colourkey when you''re creating the DirectDraw
surface, using:

ddck.dwColorSpaceHighValue = colourkey;
ddck.dwColorSpaceLowValue = colourkey;

Then in DrawSprite, just specify KEYSRC and don''t bother with the ddbltfx. colourkey depends on your video mode of course.

I''d also recommend putting together a string lookup table for directdraw errors, then using the FAILED macro to check for them and print a string.

Hope that helps

Share this post

Link to post
Share on other sites