Book Image

iOS Game Programming Cookbook

Book Image

iOS Game Programming Cookbook

Overview of this book

Table of Contents (19 chapters)
iOS Game Programming Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Moving characters


The most interesting part is making some character live, which we are going to do in this part. We will be detecting a touch on the screen and then applying some cool actions on some nodes, that is, moving the spaceship up and down.

Getting ready

To make the character move, you should know the basic actions (SKAction) that can be applied on nodes (SKNode).

How to do it...

Now, as we have got the spaceship moving in infinite space, it's time to add some more fun in the game. We will now be adding the up-down motion to our spaceship. Perform the following steps to add the up-down motion to the spaceship:

  1. Declare some properties for actions, namely up and down actions in FSMyScene.

    @property (nonatomic, strong) SKAction*         moveUpAction;
    @property (nonatomic, strong) SKAction*         moveDownAction;
  2. Define the distance and over what time the spaceship will move on a screen touch just above the implementation of FSMyScene.

    static const float SPACE_BG_ONE_TIME_MOVE_DISTANCE =...