Combining Matrices with ID3DXSprites

Started by
4 comments, last by Dave Hunt 18 years, 5 months ago
I'm doing a 2D sidescrolling game with Visual Basic.NET and DirectX 9. I've decided to use the ID3DXSprite interface instead of hard coding it with vertex buffers, vertices and you-name-it. I would like to know if it's possible to transform the Sprites by using Matrices. Example: Mirror the Sprite by using Matrix.Scaling(-1,1,1) or something; or maybe transpose the sprite etc etc. The main reason for why I want to do this is because I want to mirror the character in my game so that he can turn around. This was very easy in DX8, where they had a "Scaling"-property in the arguments of the Draw sub. But apparently, this doesn't work in DX9. So I started to wonder if I maybe could use the functionality of the Matrices to make the mirroring (and eventually get some other nice effects as a bonus). I'm using the Draw2D command, maybe there's something else that is better in this case. Thanks!
Advertisement
Have a look at the Transform property of the Sprite class.
Yeah, I've been trying a couple of things with the Transform property. But I haven't been able to get any visual results. Sure, I can scale and transpose the matrix, but how do I connect it with the Sprite. My Sprite stays unaffected.

Here's some of my code

    Dim m As Matrix        D3DDevice.SetTexture(0, texBackGround)        D3DDevice.Clear(ClearFlags.Target, Drawing.Color.White, 0, 0)        D3DDevice.BeginScene()                        MySprite.Begin(SpriteFlags.AlphaBlend)                 m = MySprite.Transform                 m.Scale(-5, 5, 0)                 MySprite.Transform = m            MySprite.Draw2D(texBackGround, Rectangle.Empty, Rectangle.Empty,                                                           Character.Center, Character.Rotation, New Point(Character.X,             Character.Y), System.Drawing.Color.White)            MySprite.End()        D3DDevice.EndScene()        D3DDevice.Present()


I guess there's one easy but important detail that I've missed. [?]

[Edited by - Muhammad Haggag on November 12, 2005 10:37:49 PM]
Try this:
m = Matrix.Identity;m.Scale(-5,5,0);MySprite.Transform = m;

Thanks for the tips. Though, it did not make any difference.

Are there maybe any special things that must be done with the Direct3D.Device before you can use Matrices?
I think the problem is that it doesn't like a negative scale factor. It should work if you use positive values. At least, it does with the non-managed SDK.

This topic is closed to new replies.

Advertisement