# Combining Matrices with ID3DXSprites

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

## Recommended Posts

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!

##### Share on other sites
Have a look at the Transform property of the Sprite class.

##### Share on other sites
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]

##### Share on other sites
Try this:
m = Matrix.Identity;m.Scale(-5,5,0);MySprite.Transform = m;

##### Share on other sites
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?

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
24
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002228
×