Jump to content

  • Log In with Google      Sign In   
  • Create Account

2d animation: best practices?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Vero   Members   -  Reputation: 138

Like
0Likes
Like

Posted 26 July 2012 - 10:23 AM

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.

Sponsor:

#2 Dir3kt   Members   -  Reputation: 166

Like
0Likes
Like

Posted 27 July 2012 - 01:43 AM

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!

Edited by Dir3kt, 27 July 2012 - 01:45 AM.


#3 nox_pp   Members   -  Reputation: 490

Like
0Likes
Like

Posted 13 August 2012 - 08:35 AM

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


#4 Lazy Foo   Members   -  Reputation: 1105

Like
0Likes
Like

Posted 13 August 2012 - 09:55 AM

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


#5 Krum110487   Members   -  Reputation: 110

Like
0Likes
Like

Posted 13 August 2012 - 11:56 AM

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

Edited by Krum110487, 13 August 2012 - 12:02 PM.


#6 Servant of the Lord   Crossbones+   -  Reputation: 19592

Like
0Likes
Like

Posted 13 August 2012 - 12:13 PM

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.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
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

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#7 hentailoli   Members   -  Reputation: 185

Like
0Likes
Like

Posted 14 August 2012 - 06:48 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS