Sign in to follow this  

C# Sprite Class - Drawing 100 sprites

This topic is 3726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been tinkering with this class, and I thought I had nearly all my issues 'solved' until I decided to draw TWO sprites instead of one. I was planning on having a Super sprite class that all used one instance of the DirectX Sprite class. Each SuperSprite would have its own matrix so that it could appear at whatever scale, rotation, and location I wanted. During the draw loop, each SuperSprite would simply set it's reference to the DirectX Sprite class's matrix its own: IE: TheSprite.Transform = MyMatrix. Then I ran into the wall... Consider the following sequence: TheSprite.Begin() TheSprite.Transform = Matrix1; TheSprite.Draw(...); TheSprite.Transfrom = Matrix2; TheSprite.Draw(...); etc... TheSprite.End() What ends up happening is that All the sprites use the last matrix set, not the matrix at the 'time of drawing'. Clearly if each sprite has its own position, rotation, and scale, this isn't going to work. I could do a TheSprite.Begin() / TheSprite.End() around each Transform / Draw pair, but from what I read, this is very 'expensive' to do. I have even tried to mess with the device matrix, but even with that, only the most recent matix assigned sticks. How do I solve this problem? How can each sprite have its own matrix without a bunch of beings and ends?

Share this post


Link to post
Share on other sites
The problem here is that Sprite.Draw doesn't actually draw, it only adds to a list for batching. The actual Device.Draws are done in the Sprite.End function so only the last transformation gets applied to the geometry.

I can't see any functions to add the transformations through software before the End call. You might have to implement your own sprite class and do the math yourself.

Edit: Another option if your transformations are simple is to just add them to the parameters in the draw call.

So instead of:

Sprite.SetTransform = Matrix.Translation( MX, MY, MZ );
Sprite.Draw( Rect, Vector3( PX, PY, PZ ) );

you'd have:

Sprite.Draw( Rect, Vector3( PX + MX, PY + MY, PZ + MZ ) );

Share this post


Link to post
Share on other sites

This topic is 3726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this