Reader small image

You're reading from  Stencyl Essentials

Product typeBook
Published inApr 2015
Reading LevelBeginner
Publisher
ISBN-139781784399450
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Richard Sneyd
Richard Sneyd
author image
Richard Sneyd

Richard Sneyd (BA Hons.) is the founder and CEO of CyberMyth Games, an indie game development studio based in Country Cork, Ireland. His role within the company requires that he wears many hats, including that of a programmer, designer, digital 2D and 3D artist, sound designer, scriptwriter, texture artist, leader, marketer, and business man. He is also a fully registered, qualified, and highly experienced lecturer. His specialty subjects include 3D modeling and animation, computer game programming, 2D image processing, game design, desktop audio, psychology, consumer behavior, human resources, and business management. In addition to classroom teaching, he is actively involved in online education, regularly publishing new courses, and various other learning materials, such as books and tutorials, in conjunction with CyberMyth Games. He is enthusiastic about his work, and his students and colleagues think of him as a very dedicated and accomplished teacher. All of his courses and books are characterized by a steady, incremental flow of information, and a lucid teaching style that is easy to understand and follow for all. He is a husband to his wonderful wife, Jennifer, and father to a wonderful son, Darius.
Read more about Richard Sneyd

Right arrow

Chapter 6. Writing Simple Behaviors

In this chapter, we will begin using Stencyl's signature visual programming interface to create logic and interaction in our game. We will create this logic using a WYSIWYG (What You See Is What You Get) block-snapping interface. By the end of this chapter, you will have the Player Character whizzing down the screen in pursuit of a zigzagging air balloon! Some of the things we will learn to do in this chapter are as follows:

  • Create Actor Behaviors and attach them to Actor Types

  • Add Events to our Behaviors

  • Use If blocks to create branching and conditional logic to handle the various states within our game

  • Accept and react to the input from the player

  • Apply physical forces to Actors in real time

One of the great things about this visual approach to programming is that it largely removes the unpleasantness of dealing with the syntax (the rules of the programming language), and the inevitable errors that come with it when we're creating logic for our game. This...

The player handler


The first behavior that we are going to create is the Player Handler. This behavior will be attached to the Player Character (PC) that exists in the form of the Cowboy Actor Type. This behavior will be used to handle much of the game logic and will process the lion's share of the player input.

Creating a new actor behavior

It's time to create our very first behavior! Go to the Dashboard, under the LOGIC heading, select Actor Behaviors, as shown in the following screenshot:

Click on This game contains no Logic. Click here to create one. to add your first behavior. You should see the Create New... window appear:

Enter the Name as Player Handler, as shown in the previous screenshot, then click on Create. You will be taken to the behavior designer window, as shown in the following screenshot:

Let's take a moment to examine the various areas within the behavior designer window. From left to right, as shown in the preceding screenshot, we have the following:

  • Events Pane: In this...

Summary


In this chapter, we learned the basics of creating behaviors, adding and setting attributes of various types, adding and modifying prefab behaviors, and even some rudimentary testing and debugging. Give yourself a pat on the back; you've learned a lot so far!

In the next chapter, we'll continue to develop the code of our game to a higher level of sophistication, implementing the user input and game rules along the way. Let's keep this momentum going!

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Stencyl Essentials
Published in: Apr 2015Publisher: ISBN-13: 9781784399450
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Richard Sneyd

Richard Sneyd (BA Hons.) is the founder and CEO of CyberMyth Games, an indie game development studio based in Country Cork, Ireland. His role within the company requires that he wears many hats, including that of a programmer, designer, digital 2D and 3D artist, sound designer, scriptwriter, texture artist, leader, marketer, and business man. He is also a fully registered, qualified, and highly experienced lecturer. His specialty subjects include 3D modeling and animation, computer game programming, 2D image processing, game design, desktop audio, psychology, consumer behavior, human resources, and business management. In addition to classroom teaching, he is actively involved in online education, regularly publishing new courses, and various other learning materials, such as books and tutorials, in conjunction with CyberMyth Games. He is enthusiastic about his work, and his students and colleagues think of him as a very dedicated and accomplished teacher. All of his courses and books are characterized by a steady, incremental flow of information, and a lucid teaching style that is easy to understand and follow for all. He is a husband to his wonderful wife, Jennifer, and father to a wonderful son, Darius.
Read more about Richard Sneyd