Game Development Reference
In-Depth Information
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 fol-
lowing 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 =
30.0;
static const float SPACE_BG_ONE_TIME_MOVE_TIME = 0.2;
3. Assign up and down actions to their respective properties in the
addSpaceShip
method as added in the starter kit project.
self.moveUpAction = [SKAction moveByX:0
y:SPACE_BG_ONE_TIME_MOVE_DISTANCE
duration:SPACE_BG_ONE_TIME_MOVE_TIME];
self.moveDownAction = [SKAction moveByX:0
y:-SPACE_BG_ONE_TIME_MOVE_DISTANCE
duration:SPACE_BG_ONE_TIME_MOVE_TIME];
4. Now implement a delegate method of
UIResponder
, which detects touches and
UI Events. The method inputs touches as
NSSet
from which any touch is taken
and converted into a position with respect to the scene on which the touch event
occurred.