Animation and logic

I have a question, not necessarily specific to any platform or API, but more specific to code interaction between animations.

The game is a good example. Let them say that the player is dying, and there is an animation of death, which must end before the object is deleted. This is typical of many cases where some animation must end before continuing with what usually happens. How would you do that?

My question is about control and animation logic. How would you create a system that can control the animation, but at the same time implement custom behavior?

The problem that usually arises is that game logic and animation data become dependent. That is, the animation should pay attention to the code or somehow contain metadata for the duration of the animation sequences. Which is typical, especially since the problem is that the animation, which should run some other code, says that after 1.13s generate a special sprite, this usually leads to a deep embedding of the code and animation. A timer bomb would be an example of both logic and animation, where both things interact, but I want to keep them as separate as possible.

But what would you do to save the animation and encode two separate things?

mgrammar, , DSL . , ...

+5
7

, . 100% , (, ). /, , (, ).

, , , " , ", . , , , . 100% .

, , - AI:

AI , , ( - / ).

, " hitreact, hitreact , , , ". , , "//", - .

- - . , , , . . !

+5

. . , . :

if(state == alive and hp == 0)
{
   state = dying
   currentanimation = animation(enemy_death)
   currentanimation.play()
}
elseif(state == dying and currentanimation.isPlaying == true)
{
    // do nothing until the animation is finished.
    // more efficiently implemented as a callback.
}
elseif(state == dying and currentanimation.isPlaying == false)
{
    state = dead
    // at this point either the game engine cleans up the object, or the object deletes itself.
}
+1

, .

- , , , , , .

, , ?

0

, .

:

  • , ( , , , ..) ( , , ,...).
  • , , , , , . , , ..
  • , , AI (, ).

, Model-View-Controller. , . deWiTTERS Guerrilla Guide to Game Code Jorrit RouwΓ© .

: , , , , , , ( ), , , " ", . , , .

. , , UnitDiedEvent, , . , . , .

.

0

, ,

asyncAnimation - "" ""

syncAnimation - , ,

, , # style

while(isRunning) 
{

   renderStaticItems();
   renderAsyncAnimations();

   if (list_SyncAnimations.Count() > 0)
   {
       syncAnimation = list_SyncAnimations.First();
       syncAnimation.render();

       if (syncAnimation.hasFinished()) 
       {
           list_SyncAnimations.removeAt(0); 
           // May want some logic here saying if
           // the sync animation was 'player dying' update some variable
           // so that we know the animation has ended and the
           // game can prompt for the 'try again' screen
       }

   }
   else
   {
       renderInput();
       handleOtherLogic(); // Like is player dead, add sync animation if required.
   }
}

, , , , . , .

, - , .

"Spawn at sec 1.13", , SyncAnimation .OnUpdate(), ( script)

.

0

, , . , , . , .

0

. , , , , .

ActionScript / . , , .

Flash, , .

, , Event, . MouseEvent, localX, localY stageX stageY. , NumberEvent, .

in the actioncript object:

var animObj:AwsomeAnim = AwsomeAnim();
animObj.start();
animObj.addEventListener(AwsomeAnim.COPLETE,_onAnimFinish);

function _onAnimFinish():void
{
    // actions to take when animation is complete here
}

In javascript where custom events do not exist. I just have a boolean variable in the animation object and check it against the timer from the controller.

in javascript controller object:

var animObj = new animObj();// among other things must set this.isComplete = false
animObj.start();

function checkAnimComplete()
{
    if(animObj.isComplete == true)
    {
        animCompleteActions();

    }else{
        setTimeout(checkAnimComplete,300);
    }
}
checkAnimComplete();


function animCompleteActions()
{
    // anim complete actions chere
}
0
source

All Articles