Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Animation sequences

DouweDabbe
Guest
Quote
2023-01-27 04:16:50

How do you code for animation sequences ?

Say i want at some gamestate to do:

Attack1 "and when that animation is finished"
Kick2 "and when that animation is finished"
Attack2 "and when that animation is finished"
Runaway

And then game state ends and transitions to some thing else

My animations get broken off as the new one comes in


just_in_case
Moderator
Quote
2023-01-27 13:17:30

There are many ways of doing it in CC, if you are using the preview build then you can utilize the new API.

you can use the code
ccbGetCurrentAnimationFrame(animatednode)
to check if the current animation frame of the animated scenenode is equal to the last frame of your animation.

For example if your animation has frames from 0-48, then you can check if the command returning the frame number = 48, then play another animation then do the same thing for other animations.


okeoke
Registered User
Quote
2023-01-27 13:34:46

Hi DouweDabbe,

Currently, I'm using states for such cases.
I.e. you have a behavior property or just a variable which represents different states:
var STATE_WAIT_FOR_ACTION_TO_COMPLETE = 'waitForActionToComplete';
var STATE_ATTACK_1 = 'attack1';
var STATE_ATTACK_2 = 'attack2';
var STATE_KICK2 = 'kick2';
var STATE_INIT = 'init;


I also define a current state variable and assign the default state:
var curState = STATE_INIT;


Then inside onAnimate function I put a switch like:
switch(curState):
case STATE_INIT:
// just switch to attack 1 state
curState = STATE_ATTACK_1;
break;
case STATE_WAIT_FOR_ACTION_TO_COMPLETE:
// do nothing here
break;
case STATE_ATTACK_1:
// start playing animation here...
ccbSetSceneNodeProperty(node, 'Animation', 'attack1');
// switch to wait for complete state
curState = STATE_WAIT_FOR_ACTION_TO_COMPLETE;
// and schedule switch to state kick
// ATTACK1_ANIMATION_TIME is your actual 'attack1' animation time in ms
setTimeout(function () {
curState = STATE_KICK_2;
}, ATTACK1_ANIMATION_TIME);
break;
case STATE_KICK_2:
// the same with other states
...
}


Also not that setTimeout function does not exist if you build for desktop, so you have to use a polyfill for that.

This approach is basically a simple state machine. I also find it very useful for coding things like AI or weapon switch/attack/reload logic.


DouweDabbe
Guest
Quote
2023-01-27 18:28:39

Thank you all !

Very usefull tips here


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact