Game Development Reference
In-Depth Information
}
}
Here you are overriding the base function
touchesBegan
. You will capture the touches
that occur and assign them to the class variable,
touchCount
. After the user releases the
touch, you have to set the count to zero; otherwise, your poor hero would always be run-
ning. You will use the
render
method in the
GameViewController
to read the
touchCount
variable in order to move the hero a direction based on how many touches
occur during that render cycle.
For this class to be used by your game, you will need to set it in the
Main.storyboard
file for the view. Open
Main.storyboard
and in the scene select the view below the
Game View Controller section. After that is selected, head on over to the Identity Inspect-
Figure 14-1
.
GameView change in Interface Builder
Now that you have the code in place to capture a touch, you need to put it somewhere you
can get the update from the scene. To do this, you will use
SCNSceneRenderer-
Delegate
and put your game logic into
render-
er.didSimulatePhysicsAtTime
. In
Figure 14-2
, you can see this is one of the last
times before the scene is drawn for you to make adjustments to the scene on a per-frame
basis.