Archived

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

DirectDraw Sprite Drawing Class

This topic is 5745 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been using DirectDraw and I can't figure out how to get this to work. I have setup a class that should work, but nothing gets rendered to the screen. When I put the exact same code that is in the class functions into my actual program, it works. Here is my class:
    
#include <ddraw.h>

#include "ddutil.h"

class cvsprite
{
public:
	int xpos,ypos,health,weapon;
	IDirectDrawSurface7 *spritesurface;
	cvsprite();
	~cvsprite();
	int LoadSprites(IDirectDraw7 *dd,char *spritefile,int loadsheetwidth,int loadsheetheight,
		int loadnumspritesx, int loadnumspritesy);
	int Draw(IDirectDrawSurface7 *buffer,int frame);
private:
	int sheetwidth,sheetheight,numspritesx,numspritesy,width,height;
};

cvsprite::cvsprite()
:	xpos(50),
	ypos(50),
	health(100),
	weapon(0)
{
}

cvsprite::~cvsprite()
{
	if(spritesurface)
	{
		spritesurface->Release();
		spritesurface=NULL;
	}
}

int cvsprite::LoadSprites(IDirectDraw7 *dd,char *spritefile,int loadsheetwidth,
	int loadsheetheight,int loadnumspritesx, int loadnumspritesy)
{
	sheetwidth=loadsheetwidth;
	sheetheight=loadsheetheight;
	numspritesx=loadnumspritesx;
	numspritesy=loadnumspritesy;
	width=loadsheetwidth/loadnumspritesx;
	height=loadsheetheight/loadnumspritesy;
	spritesurface=DDLoadBitmap(dd,spritefile, 0, 0);
	if(!spritesurface)
		return -1;
	return 0;
}

int cvsprite::Draw(IDirectDrawSurface7 *buffer,int frame)
{
	if(!spritesurface)
		MessageBox(NULL,"Error","Never created the sprite surface",MB_OK);
	int zx=0,zy=0,findframe=0;
	RECT r;
	r.left=r.top=0;
	r.right=r.bottom=64;
	backbuffer->BltFast(0,0,spritesurface, NULL,
	DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
	return 0;
}  
Frame is something that I added but I don't need it while I'm debugging, so I took it out for now. It's pretty much just which frame on the sheet should be rendered. I'm loading in tile sheets so that's what the whole sheet thing is. How I call this is like so: Making a sprite using the class: cvsprite mainchar; In the Init function: mainchar.LoadSprites(dd,"circles.bmp",256,64,1,1); In the main function: mainchar.Draw(backbuffer,0); Thanks for all the help Edited by - Badone on March 24, 2002 2:31:25 PM [/source] Edited by - Badone on March 24, 2002 2:31:53 PM

Share this post


Link to post
Share on other sites