Jump to content
  • Advertisement
Sign in to follow this  
DigiEric

Sprite animation & vertex buffer question

This topic is 4103 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

Hey all, Quick question. Say that I have my own sprite class that contains a vertex buffer that holds 4 verts, a d3dxtexture object, some texture coordinates, and a rect to determine which animation to draw from my texture. So, in my texture, I have 5 different animation frames for one object. How would I go about getting the current animation out of that texture when it's time to call SetTexture()?

Share this post


Link to post
Share on other sites
Advertisement
Hey Mike,

Actually, what I'm wondering is how I actually get the pixel data out of the texture for each animation. Kind of like how D3DXSPRITE does it:

LPD3DXSPRITE sprite;
LPD3DXTEXURE tex;
RECT animRect;
int curAnimFrame;
int spriteWidth, spriteHeight;
D3DVECTOR3 pos;
...
loadtexture(...)
...

curAnimFrame = 1;

pos.x = 100;
pos.y = 100;
pos.z = 0;

animrect.top = 0;
animRect.left = curAnimFrame * spriteWidth;
animRect.right = animRect.left + spriteWidth;
animRect.bottom = spriteHeight;

sprite.draw(tex, animRect, NULL, &pos, D3CCOLOR(255, 255, 255) );


Every time I want to change animation frames, I just have to change animRect. Well, I would prefer using vertex buffers over LPD3DXSPRITE.

Share this post


Link to post
Share on other sites
If the animation frames are all contained in one big texture, you'll need to change your texture coordinates for your vertices based on which animation frame you're drawing. You don't want to actually "reach in and grab" the raw texture data with the CPU, since causes the CPU and GPU to lose their synch and will drop your framerate. If you're using shaders it would be easy enough to offset your texture coordinates based on your frame and number of frames, but I'm not very familiar with the fixed-function pipeline so I can't help you out with that one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!