Jump to content
  • Advertisement
Sign in to follow this  
TheSilverHammer

C# Sprite Class - Drawing 100 sprites

This topic is 4011 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
Advertisement
What does TheSprite.Transform and TheSprite.Draw actually do?

Do you assign the transformation matrix to the DirectX device in the first and use a Draw(Indexed)Primitive call in the latter?

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
So it may internally cache the sprites and then dump them all at once? What would the efficency be of my own sprites vs the built in class assuming the coding I did was reasonably good?

What about the Sprite.Draw2D command?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!