Sign in to follow this  
choffstein

Animating using texture coordinates

Recommended Posts

choffstein    1090
Okay, I am still getting this 3d stuff down, but can texture coordinates be used for animation of 2d sprites? For my next game, I am using a 3d terrain with 2d billboarded sprites ontop of the terrain -- but the sprites are 2 triangles (GL_QUAD). Can I load the sprite animation all as one big texture? Lets say there are 2 animations -- =) and =(. Each one is half the space, like this:
------------------
|                |
|   =)       =(  |
|                |
------------------
Could I animate it by doing something like this: Frame 1: Quad texture coords
(0,1)    (.5,1)
-----------
|         |
|         |
|         |
-----------
(0,0)     (.5, 0)
And then the next frame, have:
(.5,1)    (1,.5)
-----------
|         |
|         |
|         |
-----------
(.5,0)     (1, 0)
Does that make sense? Would the first frame then be =) and the second frame be =(? Does this make sense to do animation this way? It would be pretty easy to implement, I would think. I also hear that a lot of games use texture coordinate manipulation to animate simple water (or, atleast a lot of older 3d games did). Does anyone have an article on how to implement this? Thanks!

Share this post


Link to post
Share on other sites
Fingers_    410
Yes, this is a good way to make animated sprites, especially if there are multiple sprites potentially displaying different frames. The less often you need to switch to a different texture the better. (For example, in a particle effects system it's a good idea to put all the different particles on one "sheet")

Share this post


Link to post
Share on other sites
I agree as well.

It's a great way to do animation, and probably the "best" way if you have more than one of that object on the screen at once (cutting out frames may be better if you have one and only one of an object because it would lead to the same number of texture changes/frame, but you'd have smaller textures).

You may even consider putting many different sprites onto a single texture, if possible. The less state changes the better.


Share this post


Link to post
Share on other sites
MasterWorks    496
For people that might not know, or want a sample image, this is a texture I use for an asteroid sprite:



I render the image sequence then use a utility I wrote to combine them into a single PNG file, then render using texture coordinates.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this