What's wrong with this code?
I''m trying to create a sprite system for my game but it just doesn''t display the sprites! Here''s the code:
void CSprite::Create( LPDIRECTDRAW7 pDD, int width, int height, int frames, int memFlags )
{
DDSURFACEDESC2 ddsd;
frameWidth = width;
frameHeight = height;
numFrames = frames;
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | memFlags;
ddsd.dwWidth = width;
ddsd.dwHeight = height;
for( int index=0; index < frames; index++ )
{
if( pDD->CreateSurface( &ddsd, &spriteFrames[index], NULL ) == DDERR_OUTOFVIDEOMEMORY )
{
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
pDD->CreateSurface( &ddsd, &spriteFrames[index], NULL );
}
}
}
void CSprite::SetBitmap( LPCSTR szBitmapFile, int bitmapWidth, int bitmapHeight )
{
hBitmap = (HBITMAP)LoadImage( NULL, szBitmapFile, IMAGE_BITMAP,
bitmapWidth, bitmapHeight,
LR_LOADFROMFILE | LR_CREATEDIBSECTION );
}
void CSprite::LoadFrame( LPDIRECTDRAW7 pDD, int frame, int x, int y )
{
HDC imageDC, surfaceDC;
imageDC = CreateCompatibleDC( NULL );
SelectObject( imageDC, hBitmap );
spriteFrames[frame]->GetDC( &surfaceDC );
BitBlt( surfaceDC, 0, 0, frameWidth, frameHeight, imageDC, x*frameWidth+1, y*frameHeight+1, SRCCOPY );
spriteFrames[frame]->ReleaseDC( surfaceDC );
DeleteDC( imageDC );
}
void CSprite::DeleteBitmap() { DeleteObject( hBitmap ); }
void CSprite::Animate()
{
if( ++AnimDelayCounter > AnimMaxDelay )
{
AnimDelayCounter = 0;
CurrentFrame++;
if( CurrentFrame > numFrames )
CurrentFrame = 0;
}
}
void CSprite::Draw( LPDIRECTDRAWSURFACE7 pDDS )
{
RECT dest_rect,
source_rect;
dest_rect.left = spriteX;
dest_rect.top = spriteY;
dest_rect.right = frameWidth+spriteX;
dest_rect.bottom = frameHeight+spriteY;
source_rect.left = 0;
source_rect.top = 0;
source_rect.right = frameWidth;
source_rect.bottom = frameHeight;
pDDS->Blt( &dest_rect, spriteFrames[CurrentFrame],
&source_rect, DDBLT_WAIT | DDBLT_KEYSRC, NULL);
}
you really expect us to debug that? for god''s sake use the html "pre" tag so it indents properly
MENTAL
MENTAL
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement