The game file that needs to be imported and loaded for this session is 5961_04_01.stencyl
.
We are going to use Stencyl's kill… instruction block to remove the collected fruit from the game, remembering that each fruit actor is a member of the Collectibles
group. Execute the following steps in order to create a behavior:
Collect Fruit
into the Name textbox and click on the Create button.We have created a new actor behavior called Collect Fruit
, which has a single empty event called Collides with Collectibles, but we haven't provided any instructions yet.
The event was initially called Actor – Group and although that is quite descriptive (we're responding to a collision between an actor and a group), we might have several Actor – Group collision events, for example, we will also need to check for collisions with actors in the Enemies group. To make it easier to identify what each event does, it's a good practice to give each event a descriptive name and, in this case, Collides with Collectibles is an appropriate name, because it describes the event that we're listening for.
Stencyl behaviors can listen out for many different types of events, but we have chosen to listen for a very specific event, which is triggered when the actor collides with any actor in the specified group. When we clicked on the Actor Group option in the orange block, and specified the Collectibles
group, we were telling the behavior to listen out for a collision event between this actor and any actor that is a member of the Collectibles
group.
The orange when block in our new Collect Fruit
behavior will listen out for a collision between Self and the Collectibles
group, but which actor is the Self instruction referring to? The answer to this question demonstrates the beauty of Stencyl behaviors, because Self is whichever actor we attach the behavior to and we can attach it to any type of actor that we want. In other words, behaviors are reusable, they are not limited to being attached to a single type of actor. They can be attached to as many different actor types as we wish.
Currently, the behavior is not attached to an actor and we have not specified what action we want to take place when the collision event occurs, so let's do that now.
3.143.203.96