Using behaviors to interact with our game

We can't really call our current creation a game, because there isn't any interaction! Players need to be able to react to what is happening in our game, or it won't be much fun so, in this part of the book, we are going to implement the following gameplay elements:

  • Controlling the monkey with the keyboard
  • Scrolling the scene as the monkey runs

Working with behaviors

Behaviors are the instructions, or rules, for our game. Currently, we have a scene and an actor, but we haven't implemented any rules relating to how our game will work.

Think of behaviors as the answers to questions that are asked when certain events occur in our game, such as the ones listed here:

  • What happens when the player presses keys on the keyboard?
  • What should happen when my actor reaches the edge of the screen?
  • What happens when my player actor bumps into an enemy actor?

The behaviors in our game can listen out for these mentioned events, and can then apply the rules that we have specified. Understanding events is a very important aspect of game development—hundreds of events will occur within our game every second, and it is up to us, as developers, to decide how we will respond to those events.

The good news is that Stencyl, as we might now expect, will manage all the hard work for us. All we need to know is that events will occur, and that our behaviors will manage how our game reacts to those events.

Adding behaviors

We are now going to start adding some behaviors into our game so that it will start coming to life! First of all, let's get that monkey moving.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.79.26