2d animation: best practices?

Started by
5 comments, last by Solano 11 years, 8 months ago
So, I've come to the point in my game were I feel I need to come past this hurtle before I move on to more complex features. I'm more or a programmer than an artist but I'm learning a few techniques for pixel/ 8bit style art. (btw what's your recommended program for making art? I'm mostly fiddling with it in MSpaint right now)

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.
Advertisement

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?

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.

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!
You can do as you say, "load a series of textures and when moving as time passes the textures would be rotated over the GL_QUAD to look like walking."

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.

Between Scylla and Charybdis: First Look <-- The game I'm working on

Object-Oriented Programming Sucks <-- The kind of thing I say

You're going to want to avoid using a bunch of textures because binding textures is an expensive operation in OpenGL. Try arranging your sprites on a set of textures in a way that you minimize the need to switch between them.

Transparency with 2D textures is easy, just enable blending and set your transparency function with glBlendFunc().

Learn to make games with my SDL 2 Tutorials

(This is slightly off topic from your question, but it relates)

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.
I use MSPaint for basic outlining and PaintShopPro XI for more advanced needs.

Paint.NET is a popular open source image editor you might want to check out.
This article will help you get started with the sprites:
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

This topic is closed to new replies.

Advertisement