Time for action – implementing touchscreen controls

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

  1. In the Ball Movement behavior, disable the Move Ball event by removing the check mark next to the behavior name as indicated in the following screenshot:
    Time for action – implementing touchscreen controls
  2. In the Ball Movement behavior, create a new always event: +Add Event | Basics | When Updating and rename it to Swipe Control.
  3. Add the instructions as shown in the following screenshot, taking care to ensure that the swiped … blocks' drop-down options are configured as shown, and that the number of degrees in each push self sharply towards … degrees at … force instruction block is entered correctly:
    Time for action – implementing touchscreen controls
  4. Mac users should skip steps 5 and 6, and move directly to step 7.
  5. Add a new when created event and rename it to Allow Gestures.
  6. Add the Enable gestures block as shown in the following screenshot:
    Time for action – implementing touchscreen controls
  7. Ensure that the mobile device is connected, and the correct device is selected in the target device drop-down list.
  8. Test the game and use a finger to swipe the screen in the up, down, left, and right directions.

What just happened?

With just a few, minor modifications, we have converted our AcceloSoccer test game to a SwipoSoccer test game!

Note

The completed sample game file, named 5961_10_04.stencyl, can be located in the book's download files.

Because we do not need the accelerometer event, we disabled it. We could have deleted it entirely, but we might want to use it again at a later date.

With the unrequired event disabled, we then created a new Swipe Control event which always reacts to the swipe gestures for each of the four detectable swipe directions. Windows developers also added a when created event called Allow Gestures, which contains the Enable gestures block.

Note

The Enable gestures block is not required according to the current Stencyl documentation. However, it was found that when developing on the Windows platform, the swipe events were not being detected on Android devices unless this block was implemented. This anomaly may be accounted for by the nature of the beta software that was being used during the production of this book, and may be resolved in upcoming updates to Stencyl.

Rather than controlling the soccer ball with gravity, which is controlled by the accelerometer feedback, we are now controlling the ball by swiping the screen in the required direction.

These are the only instruction blocks required to react and respond to touchscreen gestures!

Note that, in addition to the swipe … instruction blocks that we have used in our test game, there is also a when the device is swiped … event, which provides the same results but offers a different way to structure the events in our behaviors. The when the device is swiped … event can be found by selecting + Add Event | Input | Swipe.

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

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