Archived

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

JSCFaith

2D Engine Using D3D (Sprite Animation Troubles)

Recommended Posts

Hey, Im writing a 2d engine using 3D. I have one question, when animating a sprite using one Bitmap with all the animations in it, will I have to open the vertex buffer and change the Texture coordinates for every frame or is there a faster/better way to do it? Thanks in advance...

Share this post


Link to post
Share on other sites
If your sprite has 8 frames of animation, you could have 8 copies of the sprite vertices with different texture coordinates, and render the correct sprite depending on what frame you want to render. If your sprites are just simple quads, this is a good way to do it.

HTH, Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates

Share this post


Link to post
Share on other sites
I think the simplest way is to use IDirect3DDevice8::SetTransform() with D3DTS_TEXTURE0 as the transform type, and pass in a matrix defining the kind of transformation (translation) required. Have a look at the SDK since there are some additional parameters required for making a texture stage ready to accept a transformation matrix. This method requires no changes to the vertex buffer and therefore has less overhead, ultimately being faster (as far as I know). Good luck.

Share this post


Link to post
Share on other sites
hmm, ok.. So let me see if I understand how to do this correctly.
I would set the initial texture coordiates to for example:

(0,0)-------(.25,0)
| |
| |
| |
(0,.25)-----(.25,.25)

This is assuming there are 16 frames in a square texture and that would be frame 1's position. Now If I wanted the second frame I would do this:


      

D3DXMATRIX Position;
D3DXMatrixTranslation(&Position, .25f, 0.0f, 0.0f);
Device->SetTransform(D3DTS_TEXTURE0, &Position);



That would move me one frame over, correct?

Well, thanks in advance.

[edited by - JSCFaith on July 15, 2002 8:40:27 PM]

[edited by - JSCFaith on July 15, 2002 8:42:43 PM]

Share this post


Link to post
Share on other sites