Author Topic: Animation Handling Library (Version 1.0)  (Read 8163 times)

Blargel

  • RAWR!
  • I'M AN ANGRY LOLI!
Animation Handling Library (Version 1.0)
« on: January 21, 2010, 08:03:39 PM »
Ever get sick of how annoying it is to do animation in Danmakufu? Or maybe you don't even know how to do animation, but would love to be able to without having to bang your head on the desk or throw your computer out your window. Well fear no more! The animation handling library is here to save the day!

With the animation library, you can make animation a breeze. It even supports multiple animated sprites at the same time and even different image files per animation frame if you wanted!

Download now!
(Read on for a quick explanation on how it works. The download includes a quick demonstration that you can run to see the library in action and look through the script to see how it works. The library itself is heavily commented to make it as easy to understand as possible.)

Okay enough infomercial parodying. I wrote a library to handle animation because I was getting annoyed at having to write retarded and redundant code. As a quick example, here is what you can do with the library.

In @Initialize:
Code: [Select]
@Initialize {
    LoadGraphic(spriteReimu);

    CreateAnimation("reimu", "idle", 4);
    SetAnimationFrame("reimu", "idle", 0, spriteReimu, 12, 0, 0, 64, 64);
    SetAnimationFrame("reimu", "idle", 1, spriteReimu, 12, 64, 0, 128, 64);
    SetAnimationFrame("reimu", "idle", 2, spriteReimu, 12, 128, 0, 196, 64);
    SetAnimationFrame("reimu", "idle", 3, spriteReimu, 12, 196, 0, 256, 64);

    CreateAnimation("reimu", "shoot", 6);
    SetAnimationFrame("reimu", "shoot", 0, spriteReimu, 4, 0, 64, 64, 128);
    SetAnimationFrame("reimu", "shoot", 1, spriteReimu, 4, 64, 64, 128, 128);
    SetAnimationFrame("reimu", "shoot", 2, spriteReimu, 4, 128, 64, 196, 128);
    SetAnimationFrame("reimu", "shoot", 3, spriteReimu, 4, 196, 64, 256, 128);
    SetAnimationFrame("reimu", "shoot", 4, spriteReimu, 4, 256, 64, 320, 128);
    SetAnimationFrame("reimu", "shoot", 5, spriteReimu, 4, 320, 64, 384, 128);

    Animate("reimu", "idle", true); //true makes it loop
}

In your @MainLoop:
Code: [Select]
@MainLoop {
    if(count==60){
        FireBulletsAndStuff;
        Animate("reimu", "shoot", false); //false makes it not loop
    }

    if(count==84){ // Wait for the animation to finish.
        Animate("reimu", "idle", true); //true makes it loop
    }
    count++;
    yield ;
}

Or if you prefer to do tasks instead:
Code: [Select]
task FireStuff {
    FireBulletsAndStuff;
    Animate("reimu", "shoot", false); //false makes it not loop
    Wait(24); // wait for animation to finish;
    Animate("reimu", "idle", true); //true makes it loop
}
Just make sure you have a yield; in your MainLoop.

And in your @DrawLoop:
Code: [Select]
@DrawLoop {
    // You can still do the usual stuff like SetAlpha or SetColor here
    // and it will affect the animated sprite.
    DrawAnimatedSprite("reimu", GetX, GetY);
}

Easy enough right? If you don't think so, then you can go ahead and just try doing animation without the help of this library. :V

Feedback and bug reports and welcome. I will be updating this library if demand is high enough.
« Last Edit: January 22, 2010, 07:18:33 AM by Blargel »
<WorkingKeine> when i get home i just go to the ps3 and beat people up in blazblue with a loli
<Azure> Keine: Danmakufu helper by day, violent loli by night.

Primula

  • EARL TYPE 222
Re: Animation Handling Library (Version 1.0)
« Reply #1 on: January 21, 2010, 11:01:35 PM »
Interesting...-downloads-

Drake

  • *
Re: Animation Handling Library (Version 1.0)
« Reply #2 on: January 22, 2010, 12:04:05 AM »
bear my children, etc

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Re: Animation Handling Library (Version 1.0)
« Reply #3 on: January 23, 2010, 10:50:20 AM »
Any way to make transition states? For example, if I want something to have a transition sprite from stationary to moving left, but I dont want that frame to be included in either the stationary or left movement animation loops.

Blargel

  • RAWR!
  • I'M AN ANGRY LOLI!
Re: Animation Handling Library (Version 1.0)
« Reply #4 on: January 23, 2010, 11:07:20 AM »
You should look at how I handled the animation in the demo script. I split up the moving left, moving right, and casting animations for Nue so that they each are actually two animations. That way when I called Animate("nue", "start move left", false);, she animates the beginning of the move left animation and then holds the last frame until another animation is called, like Animate("nue", "stop move left", false);.

Basically something like:

Animate("nue", "start cast", false);
Wait(120);
Animate("nue", "stop cast", false);
Wait(16);
Animate("nue", "idle", true);


In your case, let's assume you have the following animations:
"idle", "start moving left", "moving left", "stop moving left"

Then, if your sprite is currently animating idle with looping, you can do:

Animate("sprite", "start moving left", false);
loop(12){yield;}; // assuming it takes 12 frames to transition from idle to move left.
Animate("sprite", "moving left", true);
while(GetSpeed>0.1){yield;} // wait until the sprite stops moving
Animate("sprite", "stop moving left", false);
loop(12){yield;}; // assuming it takes 12 frames to transition from move left to idle.
Animate("sprite", "idle", true);


The point of this library was to handle animation and animation only, though. What you're talking about is animation chains, or how animations chain together. That would be handled in a separate library that builds on top of this one. For now, until I decide that it's needed, you're on your own about that.

EDIT: So many edits. Sorry people. Just trying to be more clear. >_<
« Last Edit: January 23, 2010, 11:20:04 AM by Blargel »
<WorkingKeine> when i get home i just go to the ps3 and beat people up in blazblue with a loli
<Azure> Keine: Danmakufu helper by day, violent loli by night.

Re: Animation Handling Library (Version 1.0)
« Reply #5 on: January 23, 2010, 11:39:17 AM »
The point of this library was to handle animation and animation only, though. What you're talking about is animation chains, or how animations chain together. That would be handled in a separate library that builds on top of this one. For now, until I decide that it's needed, you're on your own about that.

 >:(

I was totally gonna
Spoiler:
ab
use your library for my player characters, but not if I can't chain things together easily! :'(

Blargel

  • RAWR!
  • I'M AN ANGRY LOLI!
Re: Animation Handling Library (Version 1.0)
« Reply #6 on: January 23, 2010, 11:45:34 AM »
You CAN chain animations together easily. At least, much more easily than if you were to build animations by yourself. You just need to put the logic together yourself instead of relying on a library to chain it together. I thought you of all people would be able to get it to work correctly.  >:(
<WorkingKeine> when i get home i just go to the ps3 and beat people up in blazblue with a loli
<Azure> Keine: Danmakufu helper by day, violent loli by night.

Re: Animation Handling Library (Version 1.0)
« Reply #7 on: January 23, 2010, 12:52:00 PM »
Haven't downloaded it yet :V

I wanted to know if stuff like that was possible before I started rummaging through it, since it could've just be easier for me to build my own animation loop rather than tune your function to suit my needs.

Blargel

  • RAWR!
  • I'M AN ANGRY LOLI!
Re: Animation Handling Library (Version 1.0)
« Reply #8 on: January 23, 2010, 01:00:46 PM »
Try it out before assuming it doesn't suit your needs then... :-

Now you got me thinking of how I can implement animation chaining easily...
I'd need to find a way to construct a data linking system out of arrays. And write a function that finds the shortest distance between links... That doesn't sounds fun at all.
<WorkingKeine> when i get home i just go to the ps3 and beat people up in blazblue with a loli
<Azure> Keine: Danmakufu helper by day, violent loli by night.

Re: Animation Handling Library (Version 1.0)
« Reply #9 on: January 23, 2010, 01:50:42 PM »
Try it out before assuming it doesn't suit your needs then... :-\

I didn't assume anything, I asked if it did!

Now you got me thinking of how I can implement animation chaining easily...
I'd need to find a way to construct a data linking system out of arrays. And write a function that finds the shortest distance between links... That doesn't sounds fun at all.

You're right, it sounds downright exciting.