User Tools

Site Tools


Part 11 - Running and Standing

Our little hero keeps running and facing the same direction.

He needs to be able to stand still when not running. To do this, we need to add an idle animation.

An idle animation would be simply playing hero frame 1 over and over. Let's create it:

DefaultKeyDuration = 1.0
KeyData1           = HeroRunGraphic1

The animation only uses the single HeroRunGraphic1 frame.

Some links are now needed. Remember, you are starting to build a graph of animations. Now that you have two animations, they can link in several ways:

  • Idle to Run
  • Run to Idle
  • Idle to Idle
  • Run to Run

We already made the first one back in Part 7. Now it is time to make the others:

Source      = HeroIdle
Destination = HeroIdle
Source      = HeroIdle
Destination = HeroRun
Source      = HeroRun
Destination = HeroIdle
Priority = 7

A note on the Priorty = 7 property for the last link. All links have a priority of 8. When the hero stops running, we want it to calculate back to the HeroIdle animation. We don't know if HeroRunLinkLoop will execute or if HeroRunToIdleLink will. Lowering the priority of HeroRunToIdleLink will ensure our hero will play the idle animation.

Next, the new idle animation need to be added to the set's animation list, and the three new links need to be added to the set's link list:

AnimationList = HeroRun # HeroIdle
LinkList      = HeroRunLinkLoop # HeroIdleLinkLoop #
                HeroIdleToRunLink # HeroRunToIdleLink

When the right key is pressed, the run animation needs to play by setting it as the target animation. And when right is released, the target is set to null, and the graph must calculate back to “Idle” as the animation to play:

if (orxInput_IsActive("GoRight"))
    orxObject_ApplyImpulse(hero, &rightSpeed, orxNULL);
    orxObject_SetTargetAnim(hero, "HeroRun");
} else {
    orxObject_SetTargetAnim(hero, orxNULL);

Compile and run. Pressing right will start the run animation, and letting go will revert back to the idle animation. But notice it takes about a second for the animation to start.

This is because of the 1.0 set as the default duration on the [HeroIdle] section. We could reduce this duration value to something smaller, but a more correct way would be to ensure that any request to play the run animation is delivered immediately:

Source      = HeroIdle
Destination = HeroRun
Property    = immediate

Run that. Much better isn't it?

That takes care of running and stopping while facing right. But what about left?

Let try that now.

Next: Part 12 – Changing Direction.

guides/beginners/running_and_standing.txt · Last modified: 2016/10/04 01:53 (8 months ago) by sausage