#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;
}
DirectDraw Sprite Drawing Class
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:
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
Anyone? I''m sorry for bumping this, not sure if you are allowed to or not, but I''m just bashing my head against the wall over this.
Where is you colour key set ?
Does DDLoadBitmap set a default colour key ?
You are using BltFast with a colour key.
note that if you set up a clipper,
BltFast won''t clip, Blt will.
Guy
Adventures in Sprite Rotation
Does DDLoadBitmap set a default colour key ?
You are using BltFast with a colour key.
note that if you set up a clipper,
BltFast won''t clip, Blt will.
Guy
Adventures in Sprite Rotation
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement