As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

119,613

Views

Beginner

Level

19

Comments

Working with Behaviors

by Joe (Updated on 2012-04-15)


Taking advantage of existing Behaviors is a great way to get a game up and running quickly.

Eventually, however, you’ll come across a Behavior that you want to tweak, or you’ll want to implement functionality for which no Behavior exists at all. For these cases, you’ll need to dive into Stencyl’s Design Mode.

Note: This article is mainly a "how-to" article that familiarizes you with our signature block-snapping interface. If you're searching for an article on how to "think" and tackle problems, that will be covered in a future article.

 

Contents

  • Creating a Behavior
  • Overview of Design Mode
  • Adding an Event
  • Defining the Event Response

 

Creating a Behavior

Let’s continue with the vertical shoot ‘em up game we were creating in our last article. We’ll see how we can create a simple laser-shooting Behavior from scratch.

1) Go ahead and click the Create New button in the toolbar, since we’ll be creating a new resource.

2) Choose the Behavior resource type, enter a name (such as "Fire Laser"), and click Create.

 

Note: You might be curious about those other modes... Both are for advanced users.

Code Mode lets you create Behaviors by writing straight-up code.
Freeform Mode lets you add arbitrary code, entirely outside our Behavior system.

 

Overview of Design Mode

After clicking Create, Design Mode appears. Let’s take a moment to get acquainted with the interface.

The main interface is divided into three parts – the event pane, the workspace, and the palette.

  • The event pane contains all of a Behavior’s events.
  • The workspace is where you define responses to the currently selected event. It also contains a trash can for disposing of blocks that you no longer need.
  • Lastly, the palette contains all of the available blocks that you can insert into responses.

 

Adding an Event

Reminder: Events are the building blocks of Behaviors. In short, they’re things that happen in your game that can trigger some kind of action, or response.

Let’s go ahead and create an event that will let our ship fire a laser.

1) Click Add Event, and select Keyboard from the Input menu.

2) An Event wrapper block pops up. When the Event is triggered, any blocks placed inside the wrapper block will be executed.

3) Notice the two dropdown boxes. if you click on one, you’ll notice you can select from multiple options. Let’s first choose a control for firing the laser.

Note: Controls are map physical keys on your keyboard to human-friendly names. If you flip to the Controls page under the game's Dashboard, you can see what physical key Fire1 maps to.


4) In our example, we have a Fire1 control defined. Select it from the list and then click OK.

 

Defining the Event Response

Now we need to define the actions that should occur whenever the Fire1 control is pressed. These actions are called the Event Response.

Specifically, we need to first create a laser Actor Type and then set its velocity.

Tip: The Search Box

We can use the search box inside the palette to help find the blocks we need. Just type in a word that appears as part of a block’s text, and press Enter/Return.

 

Part 1 - Finding Blocks

1) Use the search box inside the palette, to find the following blocks:

 

2) While holding the Alt key, drag the x of [Self] block to a new location to create a copy of the block.

Tip: Holding Alt and dragging a block will automatically clone it.


3) Click the x dropdown of the new block, and change its value to y.

 

Part 2 - Fill in the Fields

The white rectangles inside these blocks are called fields. You can change a field’s value in several ways:

  • By clicking the gray down arrow and selecting a block

     
  • By dragging in a compatible block from the palette

     
  • By typing in the field directly

 

Part 3 - Fill out the Event

4) Use your drag-and-drop, point-and-click, and typing skills to create the following logic snippet, and “snap” it inside the Event wrapper block, like so:

In words, we’re creating a bullet Actor 20 units above the player’s ship and are setting its vertical speed to -20 (meaning 20 in the “up” direction).

Note: See this article if you’re wondering what a “recycled” Actor is.

5) If you want to test the Behavior out, attach it to your ship like we did in the previous article, or use the Attach to Actor Type button.

 

A Recap

That's all there is to building a simple Behavior. Assuming you know what kind of logic you're building, it's a matter of gathering blocks via whatever method you're comforatable with, filling in their blanks, and piecing them together into a functional stack that represents the functionality you desire.

 

Summary

  • Stencyl’s Design Mode is divided into three parts – the event pane, the workspace, and the palette.
  • The event pane contains all of a Behavior’s events.
  • The workspace is where you define responses to the currently selected event.
  • The palette contains all of the available blocks that you can insert into responses.
  • Blocks contain dropdown boxes and fields, which can be customized.
  • The search box can help you find blocks quickly.
  • Click and drag while holding the Alt key to copy a block.
  • The Attach to Actor Type button is a quick way to assign a Behavior to an Actor Type from within Design Mode.

 

Challenge: A New Weapon

Add a second event to the Behavior that causes the ship to fire a different weapon when a “special attack” control is pressed.

Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

19 Comments

Ligaciputrawin
Dalam dunia kasino online yang penuh warna dan pilihan, Ligaciputra menonjol sebagai platform yang menawarkan tidak hanya beragam permainan tapi juga kesempatan nyata untuk menang besar. Artikel ini mengupas tuntas bagaimana Anda bisa memanfaatkan sepenuhnya apa yang ditawarkan oleh Ligaciputra untuk menjadi pemenang.

Kenali Platformnya
Pertama dan terpenting, memahami platform adalah kunci. Ligaciputra menawarkan antarmuka yang ramah pengguna dan navigasi yang intuitif, memastikan Anda bisa menemukan permainan favorit Anda dengan mudah. Dengan beragam pilihan dari slot klasik hingga kasino langsung, memilih permainan yang sesuai dengan selera dan keahlian Anda adalah langkah awal menuju kemenangan.


0 8 months, 3 days ago
Chris24XD
You need to update the page because recycled actor create block isn't exists anymore.
1 4 years, 6 months ago
sogcode003
,,,
-1 5 years, 3 months ago
Holypeanut187
Im making a run n gun game and i want the bullet / lazer to go in front of my character like a real gun and not go straight up
0 6 years, 10 months ago
wbhyvong
how to create fire behavior, in the direction of the animation. please help, very grateful.how to create fire behavior, in the direction of the animation. please help, very grateful.
0 8 years, 3 months ago
wbhyvong
how the enemy while walking toward to automatically shoot toward the right, toward the left, then shot toward the left, please help me, thanks.
1 8 years, 3 months ago
Jon
@Pluto and anyone else wondering:

Menu > View > Reset Layout

0 9 years, 3 weeks ago
Pluto14
I don't have the event pane and the palette. The only thing I have is a workspace and a trashcan, and when I rightclick with my mouse I can't place a block. Can anybody help me?
0 10 years, 4 months ago
zencylmaster
Just a direct link to the player on Vimeo...

http://player.vimeo.com/video/49919 132

Done for now. Thanks to authors of earlier comments for pointing me in the right direction! -Zencylmaster

0 12 years, 1 month ago
zencylmaster
Embed Code for Vimeo showing the workaround...

<iframe src="http://player.vimeo.com/v ideo/49919132" width="500" height="340" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></ifr ame>

Enjoy. -Zencylmaster

0 12 years, 1 month ago

Sign In to Comment