Time for action – creating a collision group for enemy actors

The game file to import and load for this session is 5961_03_07.stencyl.

We're now going to configure the collision detection, so that the monkey will collide with the enemy Croc.

  1. Display the Stencyl Book Croc actor in the Animation Editor (click on the Dashboard tab, then Actor Types and double-click on the Stencyl Book Croc thumbnail).
  2. Click on the Properties button in the row of buttons at the upper-center of the screen.
    Time for action – creating a collision group for enemy actors
  3. Click the Edit Groups button in the Choose Group section to display the Collisions Groups window in the Game Settings dialog box.
  4. Click on the Create New button at the top of the dialog box.
  5. In the Create a New Group… dialog box that appears, type Enemies into the Name textbox and click on the Create button.
  6. Look at the bottom of the list in the right panel, and we can now see that the new group has been added to the list.
  7. In the main panel, click on the Players button and the Tiles button.
  8. Click on OK to return to the Stencyl Book Croc Properties window.
  9. In the Choose Group section, click on the Group drop-down list and select Enemies.
  10. Test the game; make the monkey collide with the Croc!
    Time for action – creating a collision group for enemy actors

What just happened?

We have created a new collision group called Enemies, which will contain actors that collide with the players and tiles, and we have added the Croc actor to this new collision group.

Creating a new collision group requires us to view the Collision Group window in the Game Settings dialog box, and then either select the group that we want to work with, or create a new group. We can then click on the buttons for the other group names to specify which other collision groups our currently selected group will collide with.

Have a go hero

The game file to import and load for this session is 5961_03_08.stencyl.

We have already created an Enemies collision group and added the Croc actor to this group, so we know how to add the Snake actor to the Enemies group by changing its collision group in the actor's Properties window.

  • Add the Snake actor to the Enemies group.
  • Don't forget to test the game to ensure that the monkey collides with the snake!

Configuring collisions for the fruit actors

The game file to import and load for this session is 5961_03_09.stencyl.

The enemy actors are now configured so that they are part of the Enemy collision group, but we haven't set up a collision group for the collectible fruit.

We have already learned the skills required for creating collision groups and for adding actors into a collision group, so our next task is to put those skills into practice and configure the collision group for the fruit.

In order to ensure that our game can detect collisions between the monkey and the fruit, we must complete the following steps:

  1. Create a Collectibles collision group.
  2. Configure the Collectibles group so that it detects collisions with Tiles and Players.
  3. Add each fruit actor to the Collectibles collision group.

Remember, to create a new group, we can either click on the Settings icon on the toolbar, and then click on the Groups option in the left panel, or we can display one of the fruit actors in the Animation Editor, and click on the Properties button for that actor, which will enable us to see the Edit Groups… button.

The buttons determining the collisions for the Collectibles group should be configured as shown in the following screenshot:

Configuring collisions for the fruit actors

When the Collectibles collision group has been created, remember to view the Properties window for each of the pieces of fruit, and change the collision group to Collectibles.

It's vital to test the game at this stage to check that all the collisions are working as expected. Make sure that the monkey collides with all four types of fruit to ensure that the collision group is configured correctly.

Note

If, when the game is tested, we find that the collisions with the fruit actors aren't working as expected, review the Time for action – creating a collision group for enemy actors section, which contains the steps for creating a new group, specifying which groups collide, and adding an actor to the newly created group.

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

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