Archived

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

Animated Textures

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

My game engine is coming along nicely and I''m now to the issue of dynamic textures. What I mean are things like "unit selection circles" (in this case, a small pulsing circle under a selected unit). I could do it with an actual flat circle mesh and scale it in realtime, but that seems wasteful. What I''ve currently done is used a simple flat square mesh with a texture on it. The texture is cycled between 4 different portions of an image, each displaying a different radius circle. the overall effect is of a pulsing circle. Note that all my textures are part of a single 256x256 texture and I simply modify my texture coords for the current portion that should be displayed based on the game clock. Is there a way to generacize this? Currently, my bit of code is very specific to doing animation for my selection circles. What I really want is a way to give an image name and a count of frames or something like that and maybe a time (for how quickly the animation should play) and then have it done automatically. Is this the right approach? Is there something built in to DX for this already? Ideas, feedback? Thanks! Onnel

Share this post


Link to post
Share on other sites
I was looking through the documentation when I came upon ID3DXSprite.
It seems like overkill considering your situation, but you might like it.

Oh, and if you want to control the timing of the animation, or give the object a name or a frame count; I dunno, maybe a class will work fine.

Maybe there''s a better way, but this is how I''d handle it.

Share this post


Link to post
Share on other sites
I checked out ID3DXSprite, but that is only usable for front facing "billboard" images (am I wrong about this?). This is useful for some things I am doing, like labels over the heads of characters and things like that, but I need animated textures on objects that are being rendered into the scene.

I can only think I''m missing something really obvious, since this sort of thing is seen in games all the time, but no one is answering here.

Thanks for the answer, though. If I am wrong about Sprites only being billboarded, please let me know!

Best,
Onnel

Share this post


Link to post
Share on other sites
No, it looks like if you use DrawTransform, it won''t be front-facing.

Anyway, use a class if you want to modify an object texture.

struct RectObj
{
float urtu, urtv; //Set Upper Right Texture Coord
float ultu, ultv; //Set Upper Left Texture Coord
float lrtu, lrtv; //Set Lower Right Texture Coord
float lltu, lltv; //Set Lower Left Texture Coord
};

class AniTexture
{
public:
int AniTextureName; //Name of the Animated Texture, you can also use strings if you like.

float fFrameWidth; //Width of one frame
float fFrameHeight; //Height of one frame
int iNumFrames;
float fImgWidth; //Width of the Texture
float fImgHeight; //Height of the Texture
LPDIRECT3DTEXTURE8 lpTexAnimation; //Texture Name

int iTimePerFrame; //Number of frames before the next frame is played.
int iProgFrame; //Number of frames since animation started
RectObj FrameCoords; //Filled in by Update Frame

void UpdateFrame(); //changes FrameCoords based on information from iTimePerFrame and iProgFrame and fFrameWidth...
};

class AniTexObjManager
{
//Manages the AniTexture Classes.
//Might want to use a linked list to reference the animated textures. Or a static array if you aren''t going to use that many. Up to you to figure out how you want this information returned.

public:
void CreateTexture(float, float, float, float, int, int); //Guess where the information passed in goes.
void UpdateTextures(); //Call this from the program
void ReturnTexCoords(float, &RectObj); //Use this in main program before drawing object.
.
.
.
};

There ya go. Up to you to improve it.

Share this post


Link to post
Share on other sites