2D Engine Using D3D (Sprite Animation Troubles)

Started by
3 comments, last by JSCFaith 21 years, 9 months ago
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...
Advertisement
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
Member of the Unban Mindwipe Society (UMWS)
Thanks for the reply. That sounds like a good Approach, I will try it.
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.
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]

This topic is closed to new replies.

Advertisement