DirectX Sprite - Multiple Instances?

Started by
6 comments, last by AtomicWedgie 16 years, 2 months ago
I am working with Managed DirectX 1.1 and am trying to support the ability to render 3 different "types" of sprites - 2D, 3D, and 3D Billboard. Now, my understanding of the DirectX Sprite class is that ideally you only want one instance of it and you want to "draw" as many sprites as you can within a single Begin and End block. As the SpriteFlags that are required to render in 2D, 3D, and 3D Billboard are all different would it make sense to have 3 instances of the DirectX Sprite class - one for each of the sprite "types" that I want to support? So, in my game loop I would start the block for each of these instances and at the end I would end the block? I hope this makes sense. Thank you.
Advertisement
You'd be best with one instance, and then just call Begin() and End() on it as required. There's no reason to have multiple instances at all.
The way I currently manage my sprites is that each one is compartmentalized within an entity. An entity could be created to render either a 2D, 3D, or 3D Billboard. The entities are rendered in no particular order. Because of the haphazard ordering I perform a seperate Begin() and End() to render the sprite within each entity.

Obviously the downside to this approach is that I am calling Begin and End a LOT.

I was just thinking that it might be better to have mutiple instances of the DirectX Sprite for each of the three different types of entities that I want to support. I would call Begin() on each of these DirectX Sprite instances at the beginning of the game loop. As each entity is rendered the sprite within it would render itself using the appropriate DirectX Sprite instance. At the end of the game loop I would call End() on each of the DirectX Sprite instances.

So, for example...

Begin Game Loop

3DSprite.Begin
2DSprite.Begin
BillboardSprite.Begin

Render all Entities

3DSprite.End
2DSprite.End
BillboardSprite.End

End Game Loop

Would this work okay?
Why don't you have each entity submit a sprite and a transform to the renderer on each update.
Then the renderer can batch all those sprites together into one begin,end block. The only difference between those 3 types of sprites are how they're transformed, correct?
hmm, make your own class for example "MySprite" and create in you gamewindow a
List<MySprite> sprites = new List<MySprite>();
sprites.Add(new MySprite("C:\\test.png"));
sprites.Add(new MySprite("C:\\test1.png"));
sprites.Add(new MySprite("C:\\test2.png"));

so than you can all the Begin and End function from the MySprite at one by using a foreach loop

foreach(MySprite spr in sprites) {
spr.Begin();
}

Maybe not the best way to do it, but it work nais :)


BTW: "Obviously the downside to this approach is that I am calling Begin and End a LOT.", I think you can't along this one :(
http://www.vectorstudios.nethttp://engine.vectorstudios.net
Good idea. My only concern is that this would mean that I would have to cache all of the sprites and draw them at the end of the render stage. This would mess up the ordering in which I intended them to render them in. As I have entities that render meshes as well, it would mean that all meshes would be rendered first - followed by all sprites. If this doesn't screw up the z-buffer then it might work.


Couldn't you have a pre-cache stage in your render pipeline that occurs before everything else gets rendered.

You could sort them as needed as you're inserting them into the container.
Thanks for all of the help.

From your responses it seems to me that my sprite entities should make a call to the renderer. The renderer will stage - and perhaps order the sprites before drawing them.

Thank you for persuading me not to use the multiple Sprite idea - this one is much cleaner.


This topic is closed to new replies.

Advertisement