Sign in to follow this  
super_serge

2D animation in a 3Dworld

Recommended Posts

Hello, I am trying to make a game for a school project using DirectX 9. It is a 2 dimensional game. However, I want to make it in a 3 dimensional space in order to be able to use the camera ( zoom, pan, etc ). Now, the way I'm planning on doing this is by drawing rectangles and drawing a different frame from each texture ( all frames of the texture are in the same file, one after another ) by moving a sort of clipping rectangle across the texture, where it only gets the part of the texture that the rectangle "sees". This is easy to do with the Draw() function, if I was to be using sprites, but because sprites do not resize( without my own calculations ), I need to use my d3dDevice to grab each frame. Is there any way to do this? BTW, if what I want seems confusing please ask for clarification. Regards, Serge

Share this post


Link to post
Share on other sites
What you can do is use sprites without scaling (just draw the image at it original size) but set your render target to a texture. Now create a quad in 3d space and apply the rendered texture on the quad.
This way you can scale and do any 3d manipulation on the quad (including ofcourse zooming, panning etc...)

If you need a more detailed information , than tell me

Share this post


Link to post
Share on other sites
I'm not exactly sure what DesignerX was getting at but...

You sound like you are trying to do a project like I did not too long ago. Basically I made a 2d fighter in a 3d world. The way I did it was to create a 3d Qaud (or two triangles that make a quad). Since it is in 3d space you can obviously zoom in and out on the quad and it looks 3d... just flat :).

To make the animation properly "animate" on the quad, modify the UV coordinates for the 4 vertices to move across the texture (if the texture has many animation frames) or just change which texture your using when you render the quad if they are all on different images.

Hope this helps,
Stephen Timothy Cooney

I'll be watching for a reply to help...

Share this post


Link to post
Share on other sites
The answer to your question is just to dynamically update the UV coordinate pairs to render each frame of animation in succession, as others have pointed out. There are a couple things you need to consider with regard to performance, though, because there's a lot of ways to get the same result in D3D and most of them are slow.

First, you want to combine as many textures as is reasonable into one file just so you can batch your quads more efficiently. All sprites/quads that use this texture should be rendered with one DrawPrimitive (unless there are layering considerations), because you don't have to interrupt the batch to 'device.SetTexture'. It sounds like you're already set up to do this...

Second, you have to be careful how you implement dynamic data when you're using the GPU and CPU together. Make sure your vertex buffers are set up for dynamic use, and try to avoid locking the VB with any flags besides DISCARD and NOOVERWRITE (there are places that explain this better than I can). Get this right and your fps will skyrocket over the naive implementations that seem natural to those of us who migrated from DirectDraw and other 2D APIs.

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