Which way of using ID3DXSprite should I use.

Started by
5 comments, last by Armadon 18 years ago
Hello, Currently I'm thinking about developing 2D game on Direct3D, I'm thinking about using ID3DXSprite and ID3DXFont to draw 2D stuffs and text. In DirectX document stated that the usage of ID3DXSprite is :-

pSprite->Begin();
pSprite->Draw();
...
pSprite->Draw();
pSprite->End();
pDevice->Present();
But there are nowhere state that, should I use only 1 ID3DXSprite object, or use separate many objects to each jobs. Assume that there are 3 layers of screen - background, foreground, and text, each layer may contains several objects. And below is my current choice:- 1. Use 1 ID3DXSprite object to the whole thing :

pSprite->Begin();
//render background objects
//render foreground objects
//render text objects
pSprite->End();
pDevice->Present();
2. Use 1 ID3DXSprite object for each layer :

pSpriteBackground->Begin();
//render background objects
pSpriteBackground->End();

pSpriteForeground->Begin();
//render foreground objects
pSpriteForeground->End();

pFont1->DrawText(pSpriteText,...);
pFont1->DrawText(pSpriteText,...);
...
pDevice->Present();
3. Use 1 ID3DXSDSprite object for each object. Or, maybe there will be another way that you prefer, please discuss. Regards, Wutipong

http://9tawan.net/en/

Advertisement
use one and only one ID3DXSprite to draw all three layers. calling begin and end like that is very ineffiecient. One of the best thing i would suggest you to do is store all your tiles in one tile sheet, that way you can draw the entire map in one draw call.
You should only use one D3DXSprite object for all your sprite rendering. It manages the textures used by your sprites to minimize state changes, so by handing sprites to different D3DXSprite objects you may end up with redundant state changes as you go from one object to the next.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Just another question about the sprite object:
What does the Flush method do? Should I use it?
The flush call tells the ID3DXSprite interface to render everything you've given it up to that call, and keep waiting for more draw calls.

There shouldn't be any reason to call it under normal use.
Sirob Yes.» - status: Work-O-Rama.
Thank you for all suggestions. :D

http://9tawan.net/en/

I'd agree with superpig on this one.

This topic is closed to new replies.

Advertisement