Sup, (sorry in advance for the poor written quality and the dumb n00bish question, I'm at work and not supposed to be onthe internet. There's a lot of quick alt-tabbing going down when the boss is about!! Gotta be quick)
Right, I'm getting well annoyed with this; I have found various sites on the internet that describe how to succesfully use sprites in Managed D3D (and c#) and perform transforms on them... I just can't seem to get it to work.
Does anyone know of a simple bit of code (not pseudo) that creates a sprite class, rotates it and then places it at coords x,y on the screen
I keep getting wierd results and would be unbelievably gratefull for a just a simple implementation.
All of the examples (*and there arent many) that i have found on the internet are either written very poorly, or go about it in a way that would be unsuitable for my game.
The game I have already made is a simple asteroids game with a black hole in the middle, guns, time slow down, gravity stuff and teleport (the usual first game of a new language/api learning process!) I made it in GDI which is toss and slow with sprites/bitmaps so I had to jstu draw lines and squares to allow it to run. Obviously I took a very long time drawing all the graphics and so thought I'd port to D3D so that my effort is not lost!
What I am looking to do is just rotate a ship around and place it at coords x,y, and also to display up to 50 asteroids. Does anyone have any tips as to how best to draw the sprites to avoid slowing things right up; i understand it's easily to code this very inefficiently.
At the moment to rotate and display the sprite I am using something along the lines of (im at work so cant remeber exactly)
sprite.begin()
sprite.tranformRotateZ(Angle)
sprite.Draw(can someone explain these overloads properly to me )
sprite.End()
Also, I am unable to use the begin(spriteflags.Aplha) ,*again can't remember exactly it tells me that it does not understand the sprite flags bit!
I think I might even be creating the sprite incorrectly, so i'd like to check that. Also, what is up with draw2D() Is it any different to draw
Oh, and if anyone knows how to use one big bitmap of all the sprite frames and just pluck what you want from that I would love to know (i haven't looked into that yet)
To anyone that can help me....my un-dying respect, i cannot believe how long i have searched the web looking for help...
I made the stupid point of telling myself that i woud port this game to D3D before I start my first little 3D game and now i feel i must finish it. I'll send the finished game to anyone who helps me (and anyone else who wants it!). AS soon as i have the code for the sprite, ill be finish in an hour or two!

2D Direct3D Sprite Rotation (such a basic problem :( )
Ramachandran.d
As for putting all your sprites on one bitmap and then drawing the bits out of it what you need to do is keep a record of which part of the main bitmap, each smaller bitmap is in.
So if you have 4 images and you put them into one bitmap file you need to also store the rect for each image inside the bitmap. I do this by having an app that loads all of the images. then copy that data into a larger bitmap and keep a text file that stores the name of the original file with the rect of that image inside the larger one.
Then when you go to draw each image you then pass a pointer to a rect describing the area the image you are trying to draw is in the bitmap.
If that makes any sense.
The rotation can be done by working out what rotation you want and using this as the rotation angle and rotation origin in the Draw parameter. So if you want to rotate the ship about its centre, give the centre of the texture as the rotation centre and the radians in the float part.
jstamets
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=669329&SiteID=1
Enjoy
ieligazit
I found through the following guide in MSDN, it's very easy to do without a matrix. Maybe I'm missing something, but take a look at this and let me know if this covers all your needs...
http://msdn2.microsoft.com/en-us/library/bb203869.aspx
Also, here's a great tutorial on animating sprites and creating a Sprite Animation Framework...
http://msdn2.microsoft.com/en-us/library/bb203869.aspx
_sun_
I don't fully understand the Matrix.Transformation2D function.
The frist and second Vector2's are listed as scaling vectors. I have played around with it enough to get how to use the second one, but I am a little confused as to exactly what the first one is doing. I also don't really understand the translation vector either. Can anyone explain this further or direct me to an explanation online somewhere The only thing I have found so far is the generic definition of the function in the knowledge base and it is less tham illuminating!
Thanks
flep
i think i figured it out...
here's my sample... for c# using 9.0c... one thing you'll notice is that Transformation2D is a static function, so you do not need to (nor can you) use an instance of a matrix.
public static void render(Direct3D.Sprite sprite){
if (texture == null)initTexture(sprite.Device);
sprite.Begin(Microsoft.DirectX.Direct3D.
SpriteFlags.None);//not sure what the flags are Matrix tranz = new Matrix();tranz =
Matrix.Transformation2D(new Vector2(0.0f, 0.0f), 0.0f, //scaling vector, scaling rotation in radians new Vector2(1.0f, 1.0f),//scaling vector i want 100% so i put 1 new Vector2(500, 256), 2.0f,// rotation center, i want middle of my 1000x512 bmp and i rotate 2.0 radians new Vector2(0.0f, 0.0f));//translation vector ... i haven't learned this yetsprite.Transform = tranz;
sprite.Draw(texture,
new Rectangle(0, 0, 1000, 512), new Vector3(1.0f, 1.0f, 0.0f), new Vector3(56.0f, 56.0f, 0.0f), Color.White);sprite.End();
}
DeanB61
http://mail.rochester.edu/~mabernet/trans2d/
or atleast looking at it...
Solomonsd21
There's two things you can do
1) Wait for the October SDK release (coming next week) that will have a sample on how to use 2D sprites.
2) Go to the website for my book http://www.apress.com/book/bookDisplay.html bID=324 and download the source code. In it is a sample for "Space Donuts", an Asteroids-like game the does exactly what you want to do. I must give fair warning though -- there's some icky bugs in the code that I just haven't fixed. My thinking is, I'll leave those as an exercise to the reader
Anyway, I hope this helps!
blackwidow25
Hey,
anyone have any useful answers for this poster... i'm having the same problem trying to rotate my sample project. Am i missing something !
<code>
public static void render(Direct3D.Sprite sprite){
if (texture == null)initTexture(sprite.Device);
sprite.Begin(Microsoft.DirectX.Direct3D.
SpriteFlags.None);//not sure what the flags aresprite.Transform.RotateX(2.0f);
sprite.Draw(texture,
new Rectangle(0, 0, 1000, 512), new Vector3(1.0f, 1.0f, 0.0f), new Vector3(56.0f, 56.0f, 0.0f), Color.White);sprite.End();
}
</code>