Sign in to follow this  
Ca-snac-aj

Please, I need your apps

Recommended Posts

Hi, I'm starting with Directx (in C#)so i would be really happy if you could send me some your code from which I can understand this - especialy I mean Sprite.Draw2D and SpriteDraw. I was looking around and I noticed that there are problems with this classes, but if you have anything that is not complicated, then please send it on casnacaj@email.cz and i will be most gratefull. Thx very much

Share this post


Link to post
Share on other sites
This is what I'm using for my sprite class wrapper:


m_Sprite.Transform = Matrix.RotationZ(m_Rotation) * // Rotation
Matrix.Scaling(m_ScaleX, m_ScaleY, 0f) * // Scaling
Matrix.Translation(m_x, m_y, 0f); // Location

m_Sprite.Draw(
m_Surface.m_Texture, // Texture
Rectangle.Empty, // Crop rectanlge
new Vector3(m_Surface.Width / 2, m_Surface.Height / 2, 0), // center
Vector3.Empty, // Offset position
Color.White.ToArgb()); // or System.Drawing.Color.FromArgb(255, 255, 255, 255));



You should have one singular sprite object and then use it to draw the textures that you load. I came up with this after much trial and error and reading through books at the bookstore. You can also use the Draw2D method, but it's just a wrapper to the Draw method anyway.

The best bet would be to go out and get the, in my opinion, best book out there on the matter: Managed DirectX 9 Kick Start by Tom Miller, one of the lead developers of the library itself.

Share this post


Link to post
Share on other sites
If you intend to be rendering a LOT of sprites I would suggest you don't use sprites. It requires too many render calls and seriously slows up the system. I used the sprite approach and I went from 800fps to 70fps when only drawing several hundred sprites. I then switched to using a dynamic vertex buffer and drawing several dozen "quads" to the screen at a time and it works infinately more efficiently. I was able to keep my framerate up near 700 or so. The trick is you have to create the verticies of the buffer in pre-transformed space -- ie. NOT creating a quad around the origin and drawing it a hundred times with different transforms, but literally writing all the quads in their proper positions to the vertex buffer and calling one (or very few) draw call(s).

This approach may be a little complicated at the moment, but keep it in mind for the future because the sprite calls has limited use.

Share this post


Link to post
Share on other sites
Quote:
Original post by rjackets
If you intend to be rendering a LOT of sprites I would suggest you don't use sprites. It requires too many render calls and seriously slows up the system. I used the sprite approach and I went from 800fps to 70fps when only drawing several hundred sprites. I then switched to using a dynamic vertex buffer and drawing several dozen "quads" to the screen at a time and it works infinately more efficiently. I was able to keep my framerate up near 700 or so. The trick is you have to create the verticies of the buffer in pre-transformed space -- ie. NOT creating a quad around the origin and drawing it a hundred times with different transforms, but literally writing all the quads in their proper positions to the vertex buffer and calling one (or very few) draw call(s).

This approach may be a little complicated at the moment, but keep it in mind for the future because the sprite calls has limited use.


The Sprite class (e.g. ID3DXSprite), properly used, performs quite well. Calls to the Draw/Draw2D functions do not necessarily equate to render calls. The draw calls are batched within the sprite interface and only get turned into renders calls when End is called. If I'm not mistaken, the Sprite interface actually does, internally, basically what you are talking about doing manually.

I recommend you stick with the Sprite interface for now and worry about advanced optimizations only when/if it becomes necessary.

Share this post


Link to post
Share on other sites
Hello, i will now look at the sprite class and quad method either, to get my own experience. But if you have anything interesting i will welcome it.
Thanks a lot.

Share this post


Link to post
Share on other sites
There is a whole series of videos/transcripts/source downloads here that covers writing a game in C# using the sprite interface. It assumes no prior experience in either C# or game programming, so it should be a good place for you to start.

Share this post


Link to post
Share on other sites

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

Sign in to follow this