Sprite class

Started by
3 comments, last by GameDev.net 18 years, 8 months ago
i have been rewriting my sprite class to use vertex buffer and texture.Previously i used D3DXCreateSprite Function to create a sprite. 1)Is it worth to implement sprite class on my own? 2)Does ID3DSprite has support for multitexture sprite , rotation,scaling and so on ? I decided to not use a FVF format but instead to use Vertex Declaration. I have D3DVERTEXELEMENT9 populated, called CreateVertexDeclaration(),SetVertexDeclaration() and now what? 3)How to create a vertex buffer with LPDIRECT3DVERTEXDECLARATION9? Any resources? 4)If VB is creating via CreateVertexBuffer() is a D3DUSAGE_AUTOGENMIPMAP and POOL_MANAGED good creation flags?
Serbia,Zrenjanin
Advertisement
Regarding your first question, I'd say that it's worth while to create your own sprite class.
As to your 4th question, myself I use D3DPOOL_DEFAULT.
1) Depends on what you need. ID3DXSprite is very fast, it got a nice performance boost in Summer 2004 SDK update.

2) Rotation, scaling etc. yes, but no multitexturing.

3) First, you create array of D3DVERTEXELEMENT9 structures. Make sure that last element in array is D3DDECL_END. Then you use IDirect3DDevice9::CreateVertexDeclaration() to create the declaration. Check out SDK docs for more details.

4)You cannot use D3DUSAGE_AUTOGENMIPMAP with vertex buffers, only with textures. D3DPOOL_MANAGED keeps a copy of your buffer in system memory, where it can be restored if device is lost. I have always used D3DPOOL_DEFAULT when creating vertex buffers.

I hope this helps. [smile]
It is indeed very worth while creating your own sprite class. This is because, dependant on the genre of the game, a sprite would contain many different attributes. For instance, a sprite in an RPG would have say MP, HP, and DF etc... whereas a sprite in a racing game would have Velocity and TireSize etc...

So what you could do is to do both. Inherit from D3DXSprite and add in your own sprite attributes. That way you can benefit from not having to reinvent the wheel, as in sprite potions etc..., from D3DX’s D3DXSprite optimizations and you will be able to fully customize the sprite.
I think rpg_code_master ought to rethink his designs. There is no good design reason a sprite should have attribute like MP, HP or DF. A higher level game entity should (for example, an NPC) and it might have a sprite attached to it. Has-A, not Is-A.

This topic is closed to new replies.

Advertisement