Programming the button

Great! Now that we have created and configured the Play Game Button, we must write an Actor Behavior that will cause it to behave like a button by reacting to the mouse's events. To do so, perform the following steps:

  1. Go to the Dashboard tab, select Actor Behaviors, and click on Create New.
  2. In the ensuing window, set Name to Play Button Handler, and click on Create.
  3. Navigate to Add Event | Input | On Actor, as shown in the following screenshot:
    Programming the button
  4. Switch the condition from enters to is pressed on, as shown in the following screenshot:
    Programming the button
  5. In the blocks palette, navigate to Scene | Game Flow | Transitions, drag out and add a switch to Scene and Crossfade block, as shown in the following screenshot:
    Programming the button
  6. Click on the Scene field, and select Choose Scene, as shown in the following screenshot:
    Programming the button
  7. A window will appear, displaying all of the available scenes. Select Level 1, and click on OK.
  8. Set for secs to 1, as shown in the following screenshot:
    Programming the button
  9. Click on Attach to Actor Type, and select Play Game Button, as shown in the following screenshot:
    Programming the button

Great job! Now, we simply need to add the button to the scene, and test the game. To do so, perform the following steps:

  1. Open up the Main Menu scene again.
  2. In the Palette tab, under Actors, select the Play Game Button, as shown in the following screenshot:
    Programming the button
  3. Under Layers, select Layer 0, which is a tile and an actor layer, and then click on the Bring Layer Forward button, as shown in the following screenshot:
    Programming the button
  4. Make sure Layer 0 is still selected, as actors can only be added to the tile layers, not the background layers.
  5. Select the Pencil tool, and then click once to add the Play Game Button to the part of the scene, as shown in the following screenshot:
    Programming the button
  6. Now go back to the Dashboard | RESOURCES | Scenes, and select Main Menu.
  7. With the Main Menu option selected, click on Mark as Starting Scene, as shown in the following screenshot:
    Programming the button

Now, when we click on Test Game, the Main Menu will be the first scene to appear. Go ahead, test the game, and try your very first button!

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

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