Using Behaviors

It’s time to make our game do something.

Behaviors make our game interactive. They’re made up of two pieces:

  • Events, triggered when something happens as our game is being played;
  • Actions, which, in turn, tell our game to do something else.

Games often have many Behaviors active at any given time, with each Behavior responsible for making a small part of the game come to life.

Though you can create custom behaviors, we’re constantly adding new Behaviors directly to the freestyle Behavior Library – so you can add many common game features with no extra effort on your part.

Let’s enable those Behavior Library behaviors now.

Title Screen

Return to your freestyle editor dashboard and open your Title Screen scene. Click the “Behaviors” tab at the top of the scene editor.

In the scene behavior manager, click the freestyle behavior library tab.

Add these behaviors to our scene by clicking the “Add to scene” button next to the behavior:

  • Click to Advance to Scene, which will make our “Play Now” button transition us to the game’s first level.
  • Play Background Music, which will play ambient music on the Title Screen.

Next, we need to configure our behaviors. Click on the “Active on this Scene” tab to configure the Behaviors we’ve enabled on the Title Screen scene.

Click on the “Click to Advance Scene” behavior to configure it. Use these settings:

  • Element: Select “Play Button”
  • Scene: Select “Level 1”

Click on the “Play Background Music” behavior to configure it. Use these settings:

  • Background Sound: Select “Title”

Level 1

Now, return to your freestyle editor dashboard and open the Level 1 scene. Once the scene is open, click on the “Behaviors” tab, and then select the freestyle Behavior Library. Add these Behaviors to our Scene:

  • Camera Follows Element Movement, which will keep our player in view even as if moves off our initial screen.
  • Victory Scene Transition, which creates a dramatic transition — with music! — when the player completes the level.
  • Hurt Player on Collision, which will reduce our health when our player runs into the water.
  • Player Collects Coin, which will manage collecting coins for us: increasing our score, playing a sound, and removing our collected coins.
  • Show Player Health, which will draw our hearts to show our player’s health.
  •  Show Question on Collision, which will show a question when our player collides (runs into) a coin.
  • Make Player Jump
  • Move Player Sideways
  • Play Background Music

Then, switch to the Active on this Scene tab and configure each Behavior as so:

  • Camera Follows Element Movement
    • Player Element: Player
  • Victory Scene Transition
    • Player Element: Player
    • Victory Variant: Idle
    • Victory Sound: Level End
    • Next Scene: Level 2
    • Transition Region: Goal Region
  • Hurt Player on Collision
    • Player Element: Player
    • Hurt Variant: Dazed
    • Health Global Variable: Health
    • Injuring Element Type: Water
    • Hurt Sound: Die
  • Player Collects Coins
    • Player Element: Player
    • Coin Element Type: Coin
    • Coin Collection Sound: Collect Coin
    • Score Global Variable: Score
    • Increment Score By: 1
  • Show Player Health
    • Health Global Variable: Health
    • Health Element: Heart
  • Make Player Jump
    • Player Element: Player
    • Jump Height: Medium
    • Jump Sound: Jump
  • Move Player Sideways
    • Player Element: Player
    • Idle Animation: Idle
    • Moving Animation: Move
    • Walking Sound: Walking
  • Show Question on Collision
    • Player Element: Player
    • Collided Element Type: Coin
  • Play Background Music
    • Background Sound: Level 1