Archived

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

GroZZleR

Sprites in DirectX 8.1 -- Any suggestions?

Recommended Posts

Hey all, How do you handle sprites in DirectX 8.1? Do you just draw boxes with textures and change the texture based on what animation they''re doing? Or what are some good ways to do sprites in DirectX 8.1? I''m at a loss for how it would work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I use a vertex buffer filled with four vertices rendered as a triangle strip for each sprite.

I am wondering if it would be better to do this:
make an array of four vertices and use DrawPrimitiveUP.

but I heard vertex buffers are better.

but what about for sprites when only four vertices are being rendered.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

struct SPRITE_VERTEX
{
float x, y, z;
DWORD color;
float u, v;
};

const DWORD D3DFVF_SPRITE = D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1;

class CSprite
{

public:

CSprite();
~CSprite() { Destroy(); }

HRESULT Create(LPDIRECT3DDEVICE8 pDevice, const int nWidth, const int nHeight, const int NumFrames = 1, const DWORD dwColor = 0xFFFFFFFF);
VOID Destroy();

HRESULT LoadFrame(int nFrame, LPCTSTR pSrcFile, DWORD dwColorKey = 0);

VOID SetDimensions(const int nWidth, const int nHeight);

VOID SetPosition(int x, int y);

HRESULT Draw(int x, int y);
VOID UpdateAnimation();

VOID SetVisibility(BOOL bVisible)
{
m_bVisible = bVisible;
}

VOID SetAnimationSpeed(int nAnimSpeed)
{
m_bAnimating = TRUE;
m_nAnimSpeed = nAnimSpeed;
}

VOID SetCurrentFrame(int nFrame);

friend BOOL SpriteCollision(CSprite* Sprite1, CSprite* Sprite2);

protected:

HRESULT CreateVertexBuffer();
HRESULT UpdateVertices();

protected:

LPDIRECT3DDEVICE8 m_pDevice;

LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;

int m_X, m_Y;

int m_nWidth;
int m_nHeight;

DWORD m_dwColor;

int m_NumFrames;
LPDIRECT3DTEXTURE8* m_Frames;

BOOL m_bVisible;

int m_nCurrentFrame;

BOOL m_bAnimating;
int m_nAnimSpeed;

BOOL m_bOneTimeAnim;

};

BOOL SpriteCollision(CSprite* Sprite1, CSprite* Sprite2);

Share this post


Link to post
Share on other sites