Thread: animation algorithm

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    animation algorithm

    I've got an algorithm that cycles through a tileset of a Mech
    walking. It uses 3 variables: TimeCounter, AnimFrame, Footing.
    TimeCounter is just an incrimental counter used for delay.
    AnimFrame represents where in the tileset to get the source image.
    Footing represents which step (ie: 0 = left foot first, 1 = right)

    Code:
    long TimeCounter, AnimFrame, Footing;
    
    //in the main game loop
    TimeCounter++;
    if(TimeCounter==150000)
    {
         if(AnimFrame==0) //center point, legs even
         {
             if(Footing==0)
             {
                AnimFrame=1;
             }
             else
             {
               AnimFrame=5;
             }
         }
         else if(AnimFrame>=1 && AnimFrame<=3)
         {
            if(Footing==0)
            {
              AnimFrame++;
            }
            else
            {
              AnimFrame--;
            }
         }
         else if(AnimFrame==4)
         {
           Footing=1;
           AnimFrame=3;
         }
         else if(AnimFrame==5)
         {
           if(Footing==0)
           {
             AnimFrame=0;
           }
           else
           {
             AnimFrame=6;
           }
         }
         else if(AnimFrame>=6 && AnimFrame <=7)
         {
            if(Footing==0)
            {
              AnimFrame--;
            }
            else
            {
              AnimFrame++;
            }
         }
         else if(AnimFrame==8)
         {
            Footing=0;
            AnimFrame=7;
          }
         TimeCounter=0;
    }
    This works fine for me, but I was wondering what any of you
    guys thought. Any suggestions on how to optimize it?

    I've attached the sprite tileset I used in testing it. Forgive the
    artwork, it's pre-Alpha stage of a game I'm working on so it's not very detailed (ie: just basic textures, etc.).

    By the way, to give you an idea of the speed of C++ vs. VB (and
    I'm sure I'm not telling you somethin you don't already know),
    this is an algorithm I had written in VB and the TimeCounter
    check value was 30 there (here I had to set it to 150000,
    because it would run TOO FAST otherwise)! Man, I love C++!!!

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    I don't see a link to the file I attached

    I don't see a link to the file I attached.


    trying again....

    added: iso shot of robot..
    Last edited by jdinger; 03-08-2002 at 03:06 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM