Archived

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

Normie

2D in D3D: What now?

Recommended Posts

Normie    122
I have a class that looks something like this:
class CDirect3D // everything relating to drawing, including
//sprites (textures), devices, etc.

{
public:
	void Update(); //just calls render right now
	void Render();
	CDirect3D(); //initializes settings and pointers
	virtual ~CDirect3D(); //releases everything

private:
	IDirect3DTexture8* m_pTextures[256]; //arbitrary limit
	IDirect3D8* m_pD3D;
	IDirect3DDevice8* m_pDevice;
	ID3DXSprite* m_pSprite;
};
 
I know I need a better way to control individual sprites, so I was thinking of enclosing the m_pTexures in another class with functions such as Move(), Draw(), etc. Would this work out, or does anyone have any better ideas? Thanks! -Normie "But time flows like a river... and history repeats." ... So...what about beaver dams?

Share this post


Link to post
Share on other sites
SikCiv    122
A good way to do it is to create a seperate sprite class to handle all the individual sprites, their screen positions, and a reference to the texture they use (0 to 255). Implementing a sprite system within the graphics system will just complicate things and may cause problems in the future.

My sprite struct looks something like this:
(I dont use classes if you havent noticed)

struct SPR
{
bool bAllocated;
long xPos;
long yPos;
float fXVel;
float fYVel;
WORD nTexture;
WORD nCurrentFrame;
RECT rcFrames[MAX_FRAMES];

.. and so on
}

SPR Sprites[MAX_SPRITES];



This way, I can assign multiple sprites to the same texture which is very handy if you use alot of small sprites.

If I need to blit a sprite, I call my Spr_Blit function which calls my Gfx_Blit function internally and takes care of the frame rects, otherwise if I just need to blit a background (a whole texture)
I would use my Gfx_Blit function.

Hope this helps





  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites