Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Stefaniii

2D Animation in Direct3D

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I''ve built a 2D graphics system in Direct3D using textured quads (ok fine, I stole it from a tutorial and modified it), I am now interested in animating my Quads. My question is, does directX provide built in functionality for something like this or should I just write my own animation engine? I figure I can save myself some work if directX has some methods for doing this already. Also what software do people use to animate sprites? The prospect of drawing 30 frames of a character jumping in msPaint or photoshop make me queasy. Speaking of frames, how many should I animate to get a nice fluid 2D animation? 20fps? 30? 60?

Share this post


Link to post
Share on other sites
Advertisement
You should implementing steady motion instead of throttling your frame rate. This will allow your game to run as smooth as possible on any machine above the minimum specification. Check out the following links:

http://www.mvps.org/directx/indexes/game_timing.htm
http://www.mvps.org/directx/articles/writing_the_game_loop.htm

As for animating a QUAD, you can use the D3DXMatrix Functions to build your matrix:

D3DXMatrixMultiply
D3DXMatrixScaling
D3DXMatrixRotationX
D3DXMatrixRotationY
D3DXMatrixRotationZ
D3DXMatrixTranslation


The just use SetTransform prior to rendering your QUAD.



Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
If you're talking about switching between different image frames in a 2D animation, I doubt there's any functions that would help you out with that in Direct3D.

It's a good exercise to write your own engine to handle animation anyways. The articles Sean linked to (particularly the one on timing) are really good. You should definitely read them over.

As for fluidity, you can probably even get away with 15 or less FPS in your animations. You don't want to go too overboard.

[edited by - glassJAw on October 10, 2003 9:59:42 PM]

Share this post


Link to post
Share on other sites
Thanks for that link to the tutorial. I would not have thought to use a variable frame rate. I may as well learn it now since not all my programs will be tetris that run at an average 200 fps.

As for the matrix functions you provided me, they aren''t usefull for my purposes. I meant animation by changing the texture on the quad, not by transforming polygons, but thanks anyways.

Here is my rough outline on how to animate a textured quad:
1. Create a large bitmap that contains all the frames of the animation.
2. Load the bitmap into memory either as a texture, or onto a surface if it is too large.
3. To begin, texture a quad with the initial texture by mapping the specific coordinates of the frame from the main bitmap.
4. After a certain amount of time has passed update the animation by mapping the next frame from the main bitmap onto the quad. If too much time has passed than skip the appropriate number of frames.

Share this post


Link to post
Share on other sites
Generally, if I want to associate multiple textures to a single QUAD; or for that matter a Mesh; I would load each of the textures into memory and cycle through them to create the animation. You can load a texture into memory using either of the following:

D3DXCreateTextureFromFileEx
D3DXCreateTextureFromFile

Then use the SetTexture command to modify to alter the texture being displayed. Keep in mind that in order for this to work; your Flexible Vertex Format (FVF) must be include the D3DFVF_NORMAL flag and each of the vertices must define their own normal.

Please note that my approach uses multiple textures as opposed to one large texture.

Hope this helps.


Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
Is there any overhead associated with having many different textures rather than mapping parts of a large texture or vice versa? I don''t know how directx works internally, so if it''s doing a lot of copying or something silly when it crops a small piece from a large texture then your way may be far more efficient.

Share this post


Link to post
Share on other sites
quote:

Is there any overhead associated with having many different textures rather than mapping parts of a large texture or vice versa? I don''t know how directx works internally, so if it''s doing a lot of copying or something silly when it crops a small piece from a large texture then your way may be far more efficient.



If memory serves Jim Adams implemented a skybox by loading one texture per face in his book and Mason McCusky implemented multiple textures per QUAD for explosions in his book. To the best of my knowledge this solution has no real performance hits. However, the primary reason for implementing multiple textures is the hardware limitation of the video card. Generally, textures are limited to 1024 by 1024 to be compatible with most video cards.

Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
quote:
Original post by Stefaniii
Is there any overhead associated with having many different textures rather than mapping parts of a large texture or vice versa? I don''t know how directx works internally, so if it''s doing a lot of copying or something silly when it crops a small piece from a large texture then your way may be far more efficient.


If you can batch drawing calls from a large texture together (so you only call SetTexture() once per texture), then yes it will be faster. Otherwise the performance hit shouldn''t be too bad.

Nevertheless, I recommend using a single large texture (but not too large) rather than a bunch of small ones.

Share this post


Link to post
Share on other sites
quote:

If you can batch drawing calls from a large texture together (so you only call SetTexture() once per texture), then yes it will be faster. Otherwise the performance hit shouldn''t be too bad.

Nevertheless, I recommend using a single large texture (but not too large) rather than a bunch of small ones.



Maybe I misunderstand your solution, how are going to map to different areas of a large texture? Are you planning on doing this at the mesh texture mapping layer?

Thanks


Understanding is a three edged sword...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!