Displaying an animated Object

edited March 2009 in Help request
Doh !! that's Tutorial 4 !!

But it's 4 hours of tests on the ini file to make something and i'm stuck.

I need some answers.
I've added an object without problems and now i'm searching how to make a little animation with just one state (looping frames).
So first I have a png file with the different state of the anim. medic.png


I use the tutorial 4's .ini file to try things but I just manage to crash the system with bad ini files.

Here are the details of the .ini file.

[Bonus_Medic]
Graphic=MedicGraphic;
AnimationSet=MedAnim;
Scale=4.0;

Can we put the Position and Body attributes ?


/// As thoses parts doesn't interact with animation ( I think ?) I put them on a single line in the forum ////////
[MedicBody]
PartList=MedicPART;Dynamic=True;FixedRotation=true;

[MedicPART]
Type=Box;TopLeft=full;BottomRight=full;Solid=true;Density=1.0;SelfFlags=0x0001;CheckMask=0x0001;
//////////////////////////////////////////////////////////

[Pivot]
Pivot=center;

[MedicGraphic@Pivot]; adds the Pivot center attribute to the graphic ?
Texture=../data/objects/medic.png;

[AnimSet]
AnimationList=Anim1#AnimIdle;
LinkList=AnimIdleLoop#Anim1#Anim1Loop;
Basicaly I want just one state 'Anim1'. But following the tuto I tried adding a second state to use the LinkList. Will the engine work without LinkList ?


[AnimIdleLoop]
Source=AnimIdle;
Destination=AnimIdle;

[Anim1]
Source=AnimIdle;
Destination=Anim1;
Priority=immediate;

[Anim1Loop]
Source=Anim1;
Destination=Anim1;

[AnimIdle]
KeyData1=Anim6@FullGraphic;
KeyDuration1=0.1;

[Anim1]
DefaultKeyDuration=0.1;
KeyData1=Anim1;
KeyData2=Anim2;
KeyData3=Anim3;
KeyData4=Anim4;
KeyData5=Anim5;
KeyData6=Anim6;

[FullGraphic@Pivot]
Texture=../data/objects/medic.png;
TextureSize={16;13;0};

[Anim1@FullGraphic]
TextureCorner={0, 27, 0};
[Anim2@FullGraphic]
......... till Anim6

Those ini sections makes the game crashes without displayin anything :
[Assertion failed] : <(orxU32)_hSrcAnim < orxAnimSet_GetAnimCounter(_pstAnimSet)>


Last thing , Do I have to set code in the EventHandler of the .c file ? I just put
orxObject_SetTargetAnim(pstBonusMedic , "Anim1");

in the Update function.


So that's lot of things i'm sorry !! I hope it won't take you more than 2 minutes to answer as you have probably better things to do !

Thanks
Mout
medic 286B

Comments

  • edited March 2009
    Moutew wrote:
    Doh !! that's Tutorial 4 !!

    But it's 4 hours of tests on the ini file to make something and i'm stuck.

    Yes, animation tutorial isn't the easiest one. I kept it simple but the concept behind is very powerful and a bit tricky to handle at first.
    I need some answers.
    Here they come! :)

    But first of all, you need to be sure to know how the animation engine works.
    Animations are placed in a graph. So each node of this graph is an animation and there are links between them that define which transitions can be achieved and which can't.

    As for example, if you use 2 anims, you can define up to 4 links: one going from anim1 to anim1 (self loop), one from anim1 to anim2 (transition 1->2), one from anim2 to anim2 (self loop) and one from anim2 to anim1 (transition 1->2).

    It's up to you to see which links you want to define or not.

    In addition to this a link can have properties and a priority.
    Let's begin with the property, right now it can only be none (default one) or immediate.

    If you create a link from anim1 to anim2, and when your object is currently playing its anim1 you run the code orxObject_SetTargetAnim(MyObj, "anim2" ), orx will find the shortest link to get from anim1 to anim2. In our example, there are 3 possibilities:
    - no link is found => won't process, anim1 will stay the current anim
    - a link is found with no property => anim1 will run till completion and *after that* anim2 will start.
    - a link is found with the immediate property => anim1 will be interrupted and anim2 will begin immediately.

    It's pretty straightforward for 2 animations, but it'll be of great help when having more animations. For example, you want your character to run. You don't need to know if he's currently standing or lying down. You just call orxObject_SetTargetAnim(MyObject, "Run" ). If he can go to run from its current state, the animation engine will find the best chaining of animations (shortest path in the graph).

    Here if he's standing up, there might be a direct link from Standing to Run in your graph, with the immediate property, which means he'll run right away.
    If he's lying, the path will contain maybe 2 links, first one being standing up with an immediate property, and second one will be run with no property so as to let the standing up animation run till its completion.

    Now for the priority, when there are 2 ways between the current anim and the target one that have the same length (number of hops in terms of animations), the highest priority link will be used to get out of the current animation. It's used most often when you want your character to go back to its "stable" state. For that, you can just do orxObject_SetTargetAnim(MyObj, orxNULL), and the next link that will be used is the highest priority one. Not sure if this is clear! ^^ But it's advanced use of the system anyway, so let's try simple first!
    I've added an object without problems and now i'm searching how to make a little animation with just one state (looping frames).
    So first I have a png file with the different state of the anim. medic.png

    So far, so good! Your animations can even be spreads across many image files, it doesn't matter to the engine.
    I use the tutorial 4's .ini file to try things but I just manage to crash the system with bad ini files.

    I need to improve this with better error messages, will try!
    Here are the details of the .ini file.

    [Bonus_Medic]
    Graphic=MedicGraphic;
    AnimationSet=MedAnim;
    Scale=4.0;

    Can we put the Position and Body attributes ?

    Yes, you can! You're defining an orxOBJECT right there, so everything coming from the ObjectTemplate section applies!
    /// As thoses parts doesn't interact with animation ( I think ?) I put them on a single line in the forum ////////
    [MedicBody]
    PartList=MedicPART;Dynamic=True;FixedRotation=true;

    [MedicPART]
    Type=Box;TopLeft=full;BottomRight=full;Solid=true;Density=1.0;SelfFlags=0x0001;CheckMask=0x0001;
    //////////////////////////////////////////////////////////

    As long as you don't do this in the actual config file, you're fine. Writing everything on the same line wouldn't work in an ini file as everything on a line after the first comment character ';' will be ignored!
    You don't need to specify the TopLeft/BottomRight coordinate if you intend to use the full size, that's orx's default settings.
    [Pivot]
    Pivot=center;

    [MedicGraphic@Pivot]; adds the Pivot center attribute to the graphic ?
    Texture=../data/objects/medic.png;

    Yep, the @ sign defines inheritance, so your MedicGraphic section inherits from the Pivot one and therefore will contain a key called Pivot with the value center. The good thing with inheritance is that you can inherit from section defined later in the same config file or even defined in an other config file. Inheritance will be computed sequencely when reading all the config files.
    [AnimSet]
    AnimationList=Anim1#AnimIdle;
    LinkList=AnimIdleLoop#Anim1#Anim1Loop;
    Basicaly I want just one state 'Anim1'. But following the tuto I tried adding a second state to use the LinkList. Will the engine work without LinkList ?

    Actually, here you have a few things that won't work. The first one is using the same name for a link and an animation. As both needs their own section, using the same name means it's a single unique section. Luckily they don't have any property in common, so they won't conflict, but it's still very confusing for someone to read.

    As you only have one animation, you also need one link to make it loop when it ends.
    So you'll have something like this:
    AnimationList=AnimIdle;
    LinkList=AnimIdleLoop;


    And now we'll define this animation and this link:
    [AnimIdleLoop]
    Source=AnimIdle;
    Destination=AnimIdle;

    That's perfect, AnimIdle leads to AnimIdle, with no interruption.

    Now let's define the anim idle like this:

    [AnimIdle]
    DefaultKeyDuration=0.1; <= By default, unless stated otherwise, every frame of this animation will last for 0.1s when played at frequency=1
    KeyData1=AnimData1; <= If you reused the same name as the animation, it'll be confusing in the same way than using the same name for a link and an animation
    KeyData2=AnimData2;
    ...
    KeyData6=AnimData6;

    [FullGraphic@Pivot]
    Texture=../data/objects/medic.png;
    TextureSize={16;13;0};

    That's a good way of using the inheritance system and saving some work on the TextureSize. Except that ';' is not the separator for vectors! ;)
    TextureSize=(16, 13, 0)
    will work better! :)
    [Anim1@FullGraphic]
    TextureCorner={0, 27, 0};
    [Anim2@FullGraphic]
    ......... till Anim6
    Perfect, except that we'll now use AnimData* in place of Anim*
    You can either use () or {} for defining vectors, up to your preference. :)
    Those ini sections makes the game crashes without displayin anything :
    [Assertion failed] : <(orxU32)_hSrcAnim < orxAnimSet_GetAnimCounter(_pstAnimSet)>
    You should be free of it now if I didn't make any mistake in here! :)
    Last thing , Do I have to set code in the EventHandler of the .c file ? I just put
    orxObject_SetTargetAnim(pstBonusMedic , "Anim1" );

    in the Update function.

    The event handler was just there to show how it work and how you can be informed of animation starting, stopping, being cut and looping. You don't have to use it if it has no purpose to you. It's mainly there for synchronizing stuff with animation (playing sound, for example).
    You can call orxObject_SetTargetAnim() and orxObject_SetCurrentAnim() from whereever you want! :)

    Here you don't have to specify the target anim as you're only using one, so it will be the default played animation.
    So that's lot of things i'm sorry !! I hope it won't take you more than 2 minutes to answer as you have probably better things to do !

    Don't be sorry, it's great to see someone using my work and I'm happy to help and give support! :) It also makes me see what's is more tricky to use in the engine. And it can even be used later in a FAQ and/or Wiki!

    Hope this helps! :)

    - iarwain
  • edited March 2009
    Hi

    That works perfectly.
    One of the case of the system crash is ( humiliation time for me ) if the definition of the AnimSet value points to nothing (like a typping error). That's a little thing that shouldn't hapend with people that correctly read thier ini files.

    Thanks for your help.
    For now, i've added 2 solid gfxs in ARSX, and now i'm having a snooker like game ;) So powerful.

    See you for the next questions ;)

    Mout
  • edited March 2009
    Hi!

    If you weren't using a correct name, in debug version you should have had a warning message telling you about this on the console and in orxDebug.txt. But I have to admit this debug output is a bit too verbose sometimes! ;)

    I'm glag things are going smoothly for now. I'm really looking forward to see what you do, guys! :)

    Awaiting the next questions! ;)

    - iarwain
  • edited March 2009
    hey Moutew!

    looking forward this pool asrx you made up =) didn't send me the code yet :P

    I think you will understand the usefulness of having a good svn client when we'll pull your changes to the repository, as iarwain did some changes on files you have been working on as well =)

    Looking forward to working on all that awaits us!

    and going to sleep now so I'll be fresh a bit earlier tomorrow, g'night!
Sign In or Register to comment.