Advertisement Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Problem solved

Sign in to follow this  


Ok, so I posted that message about problems with text and rendering them in surfaces with proper Z ordering in Managed DirectX before.

I found a solution. I will just post here in case any of you have the same problem.

In Microsoft.DirectX.Direct3D.Sprite class, there's a Matrix property name Transform that lets you handle all of these, but has a slight problem in it:
The transform is not applied per sprite, but it's per batch. So if you set the transform, call Sprite.Draw, then another transform and another Sprite.Draw, then EndSprites, only the last transformation is applied.
The solution is to call Sprite.Flush after each render. Now that poses another problem that having the Sort order (back to front, front to back, by texture, ...) are totally useless now since you're not sprite batching anyways. This is going to be when you need some bit of smart coding. Basically, you need to call the sprite render function in order of the sprites. It works fine once you get the hang of it, and it works for Direct3D.Font class as well.
You can apply rotations really easily this way, just don't forget to move the rotation centre of sprite to origin first before rotating. For flipping (in case you're doing all 2d) you can just do a Yaw of pi radian.

Anyways, it looks pretty nice now. I can get on with the rest of my project
Sign in to follow this  

1 Comment

Recommended Comments

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
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!