2d animation: best practices?
#1 Members - Reputation: 138
Posted 26 July 2012 - 10:23 AM
anyway here's run down of questions I have.
Whats the best way to creating a sprite in openGL, right now I would simply load a series of textures and when moving as time passes the textures would be rotated over the GL_QUAD to look like walking, Is there a better/ cleaner way to implement this in a 2d environment?
How would I go about creating transparency on parts of the texture? I've tried to implement a few examples of Masking but so far I haven't had any success, would I need to use something other than .bmps for this, e.g. .png
Thanks for any advice you can offer.
#2 Members - Reputation: 163
Posted 27 July 2012 - 01:43 AM
Most 2D game engines use texture atlas (google it if you don't know it). The basic idea is to create one big texture containing all the sprites (enemy anims, player anims, projectiles, ...) and then use uv coordinates to map regions to the quads. The big advantage is you have to bind the texture only once for all the sprites which is a huge performance gain.Whats the best way to creating a sprite in openGL, right now I would simply load a series of textures and when moving as time passes the textures would be rotated over the GL_QUAD to look like walking, Is there a better/ cleaner way to implement this in a 2d environment?
Actually this is more less like your idea of rotation the texture.
How would I go about creating transparency on parts of the texture? I've tried to implement a few examples of Masking but so far I haven't had any success, would I need to use something other than .bmps for this, e.g. .png
Yes simply use the alpha component of PNGs.
Good luck with your game!
Edited by Dir3kt, 27 July 2012 - 01:45 AM.
#3 Members - Reputation: 427
Posted 13 August 2012 - 08:35 AM
But it's more expensive than just loading one texture, a spritesheet/texture map, and modifying the texture coordinates as time passes to point to different parts of the texture. This solution is a little more difficult to implement though, and your first solution will work fine and be performant enough as long as you don't have too many things being animated at once.
Either way, you'll also probably want some way of "defining" animations outside of the code. Historically, I've used both XML and Lua for this.
#4 Members - Reputation: 1029
Posted 13 August 2012 - 09:55 AM
Transparency with 2D textures is easy, just enable blending and set your transparency function with glBlendFunc().
Transition from OpenGL 2 to modern OpenGL using my OpenGL Tutorial.
#5 Members - Reputation: 110
Posted 13 August 2012 - 11:56 AM
just for some specifics on animation, I am not keen on OpenGL (getting there), but I have drawn sprites, I used this technique, I made 8 images for each direction (except only 1 for left and right since it can be flipped), each one I assumed was at a 4 pixel pace (aka 4 pixel movement between each frame) so this is how it worked in code:
pseudo code:
while moving right
move 4 pixel
go to next frame
otherwise if you were to simply animate it separate of movement you will get floating foot syndrome, where they look like they are doing a moon walk forward or something.
of course the more frames you have the better it will look, so once you get a sprite system, you will have a nice method of animation, that looks like the steps they are taking are moving them.
As for the program to use, MSPaint is fine, albeit limited, and it depends how 8bit you want to go, if you want to look like a nintendo game, mspaint is great, you can use photoshop if you want more tools and layers, you simply have to limit the pallet to 8 bit colors.
Edited by Krum110487, 13 August 2012 - 12:02 PM.
#6 Marketplace Seller - Reputation: 8947
Posted 13 August 2012 - 12:13 PM
Paint.NET is a popular open source image editor you might want to check out.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#7 Members - Reputation: 184
Posted 14 August 2012 - 06:48 AM
http://www.gamedev.net/page/resources/_/technical/opengl/rendering-efficient-2d-sprites-in-opengl-using-r2429
You will find this series of tutorials very helpful:
http://www.codeproject.com/Articles/27219/TetroGL-An-OpenGL-Game-Tutorial-in-C-for-Win32-Pla






