Time for action — iPhone acceleration

For this section, we are going to use the iPhone's accelerometer to move our player back and forth.

  1. Within the iPhone Movement group, create a new rule and name it Accelerometer, changing the settings to Attribute: | game.Accelerometer.X |> | 0.
  2. Then, we drag in a Move behavior and change the settings to:
    • Direction:90
    • Speed:100

      Everything else can remain the same.

    Time for action — iPhone acceleration
  3. Now, duplicate that rule and change it from> 0 to< 0 and change the Direction to 270.
  4. Create two new attributes back in the Inspector, both of them will be Booleans, one called Left and the other Right, very simple.
    Time for action — iPhone acceleration
  5. We have to do some more touch controls. Create two new actors, also named Left and Right. Open the Left one up and we are going to edit it. Change the Size by making the Width 240 and Height 320. Now, let's create a new rule and change it to Actor receives event | touch | is | pressed.
  6. Then, drag in a Change Attribute and change it to Change Attribute: | game.Left | To: | true.
  7. Expand the Otherwise roll-out, and drag in a copy of the last Change Attribute behavior and change it from true to false.

    The settings are shown in the following screenshot:

    Time for action — iPhone acceleration
  8. Finally, drag in a Change Attribute and change the settings to Change Attribute: | self.Color.Alpha | To: | 0.

    This will hide the actor as soon as we hit play.

  9. Now, let's go to the Right actor and add in the same rule and behaviors, but of course change it from game.Left to game.Right.
  10. Now, let's go to our Player actor and in our iPhone Movement group, create a new rule and change it to Attribute: | game.Left | To: | true.
  11. Now, let's drag in a Rotate behavior, and change the settings to the following:
    • Direction:Counter-Clockwise
    • Speed:200
  12. Simply duplicate that rule, change it from game.Left to game.Right, and change the Rotate direction to Clockwise, it's that easy!
    Time for action — iPhone acceleration

What just happened?

In this section, we looked at making our player move using the device's accelerometer. Then, we set up two Booleans that when triggered (or turned to true) made our player rotate left and right accordingly.

That's it for the iPhone controls! Now, we are done with the main development of the game; all you have to do from here is finish the rest of the levels.

Have a go hero

Why not try out your own type of controls, such as two thumb sticks to control and rotate the player. Not sure how to do that? Why not take a look at the Official Cross-Platform Controller Template in the new section of projects, examine the behaviors and give it a try.

Have a go hero

The two thumb stick controller looks something similar to the previous screenshot; it makes the gameplay much better. Some people don't like accelerometer controls, so why not give the player a choice at the beginning of the game to select accelerometer or touch controls? This would be done with a simple boolean attribute that will be checked through the whole game; if the Boolean is true, use tilt controls, if it's false, use touch controls. It's simple!

Now that we are done with developing the game (in terms of gameplay), in the next chapter we will be setting up the player leaderboards, testing the game on our devices, preparing the game for the App Store, and then finally deploying it for the App Store! This is where the fun begins! You are getting closer and closer to making money on your own creation. Isn't it exciting? Once you see your creation on the App Store, you are going to be so excited and then you'll see the reviews coming in, and most importantly the paychecks!

Pop quiz

  1. How do you prevent an actor from moving on collision?

    a. Add in a rule that constantly sets the player's speed at 0

    b. In the Actors attributes under Physics uncheck Moveable

    c. Set the player's maximum speed to 0

    d. None of the above

  2. True or False: You can change the actor's colors on the fly.

    a. True

    b. False

  3. How do you do a multi-condition rule?

    a. You can't

    b. Add a second rule into the current rule

    c. Click the + button inside of the rule's condition

    d. None of the above

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

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