Rotating Nodes

Now the hero stands in the right spot, but he or she looks boring in contrast to the exciting animated ground. Instead of making the sphere stationary, how about if you roll it over the striped bar? You can create this effect by rotating the player’s avatar on each frame. Add the following code to the update method of PlayScene:

//rotate the herovar degreeRotation = CDouble(self.groundSpeed) * M_PI / 180self.hero.zRotation -= CGFloat(degreeRotation)

You have to define the groundSpeed constant, too. Write it as an integer-type property of PlayScene. The ground speed indicates how many degrees the sphere should rotate per frame. Converting the degrees to radians requires a bit of math. We play around ...

Get Learning Swift™ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.