• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

There got to be a better way to manage animations.

7 posts in this topic

Somes weeks ago, i've started pouring more hours on the animation part of my game, which was pretty bare up to this point. After sucessfully creating a tool to easily create and modify my 2d animations from a sprite sheet (setting things like sprite rect, crop, hitboxes, weapon mounting point and angle, etc...), i now have to actually do the logic of switching all of the animation the actors have in the game.


The code below is my function to change the actor's animation based on his state.

While, i've not actually come to a dead end, i feel what my code is starting to feel tangled and harder to debug.

As you will notice a little bit further down, it'll only get more complicated, as the number of possible animation is very wide.


So my question is this: Is there a better way of doing this? Or should i just continue doing all thoses else-if?

I really do not want all the hours i'm doing to go to waste if i have to redo everything, especially all the time spent doing my own animation tool (which is very specific to my game).

void IActor::ManageAnimation()
    Animations id = ANIMATION_IDLE_OOC;
    //If out of combat
    if(!IsState(STATE_INCOMBAT) )
            id = ANIMATION_JUMP_OOC;

        else if(IsState(STATE_FALLING))
            id = ANIMATION_FALL_OOC;

        else if(IsIdle(MAX_IDLE_TIME))
            id = ANIMATION_SLEEP_OOC;

        //Sliding show be shown over moving
        else if(IsState(STATE_SLIDING))
            id = ANIMATION_SLIDE_OOC;

        else if(IsState(STATE_MOVING))
            id = ANIMATION_MOVE_OOC;

enum Animations
    //Generic animation. Everyone should have theses. It's the job of this class to set them.
    //Out of combat
    ANIMATION_IDLE_OOC,            //Basic idle animation out of combat.
    ANIMATION_SLEEP_OOC,        //Animation for idling too long... Player yawn, wolf lay down and sleep, etc...
    ANIMATION_MOVE_OOC,            //Moving
    ANIMATION_LOOK_UP_OOC,        //Look up
    ANIMATION_LOOK_DOWN_OOC,    //Look down
    ANIMATION_TREATHENED_OOC,    //Transition between out of combat and in combat.
    ANIMATION_JUMP_OOC,            //Jump
    ANIMATION_FALL_OOC,            //Falling
    ANIMATION_SLIDE_OOC,        //When the actor is changing direction or sliding down a slope.

    //In combat
    ANIMATION_IDLE_IC,            //Basic idle animation in combat.
    ANIMATION_MOVE_IC,            //Moving
    ANIMATION_LOOK_UP_IC,        //Look up
    ANIMATION_LOOK_DOWN_IC,        //Look down
    ANIMATION_TREATHENED_IC,    //Transition between in combat and out of combat.
    ANIMATION_JUMP_IC,            //Jump
    ANIMATION_FALL_IC,            //Falling
    ANIMATION_SLIDE_IC,            //When the actor is changing direction or sliding down a slope.

    //End of generic animation

    //Specific animation. Not everyone have them. It's the job of the Actor's interface to set them. thoses animation can all be canceled by us.
    //Reserve for physical attack with a weapon or unarmed.

    //Reserved for Spell animations

    //Reserved for social animations. could be laugh, cry, angry, yell, etc...
    //End specific animation
Edited by Sunsharior

Share this post

Link to post
Share on other sites

Thank you for your reply, Krohm (and everyone else). Quoting you, I will explain a bit further how i currently handle my animations.



Your whole problem arises because you're trying to enumerate the animations. This is a fundamentally wrong way to a approach the problem. Animations states are strings, and they are asset-specific. You don't map them to uints, you can do it, but it really isn't a sensible way of authoring assets.

Animation names are strings. So you can have very specific animations such as PlayModelAnimation("cutscene4_bridgeCollapsed_teammateAlive") where your avatar and the sidekick note how they were doing great so far, but also have to cut another few seconds next time.


I do have a "PlayAnimation" function that is called during cutscene. this function do not depend on the state of the actor, as it is only processing scripted animations. But this is somewhat irrelevant to my problem here.

What i'm describing in my post is during normal gameplay (Nothing scripted here). This depend heavily on the state of the actor, for example, if he is currently underwater, or jumping, or swiging his sword, etc... What im trying to do here is, at the end of my frame, i check what happened to the actor as a whole and set the animation correctly. Let say in a single frame, the actor moved right, but also got hurt, i need to prioritize showing the hurt animation for the next couple frames before resuming showing moving right.



I'm having myself some problems however in understanding how this could work for you since your IsState function seems to be smarter than I'd suggest to - so something is falling... or jumping... in combat or not. So basically IsState does non-trivial checking of variables which are of your own design.


IsState is simply an array of boolean that contain the state of a very specific actor. It can be things like "in combat", "falling" or "jumping". A complimentary function SetState does the work during user input (or AI) to set the appropriate states.



In my design, I don't set animation as part of the loop. I start them event-based so no state polling is required and I found this to be a rather good solution so far.


If i could do the same thing without the state polling i would be very happy. I'll try to explore Finite State Machine, which i am aleredy using for the user input / Ai function and see if i can use it too for the animations.


I think mikeman's answer i what i'll be looking into first, thought, as it is very close to what i'm currently trying to do.


Of course i will take time to really think this through. Heck, maybe putting the ManageAnimation code inside my Iactor class is innapropriate, as the actor truly care only to keep track of it's current animation and frame, as DareDeveloper aleredy said is true.

Edited by Sunsharior

Share this post

Link to post
Share on other sites

Your animation management appears to be a finite state machine, which doesn't need to be hardcoded with constants and ifs and enums.

Instead, you should define a data structure to represent animation definitions, loaded from external files and processed by a generic animation manager. Your current ManageAnimation method is in class IActor, but it isn't generic: it assumes a number of states and events exist.

This is spot on. Read this for a great introductory tutorial to creating FSM's.


Here's another one which uses Enumerations, but is still very general. It might be easier for you to use this one, because it somewhat follows your current train of thought.


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  
Followers 0