O'Reilly logo

Getting Started with SpriteKit by Jorge Jordán

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

1-star challenge: an easier way to reset position

I chose the solution of running two actions in order to recover the initial position because I wanted to introduce you to sequences, but there is an easier and fancier way of achieving the same result. With the knowledge that you have so far, try to get the same results that you got when using a sequence.

Solution

The key to this challenge is to use the runAction(_:, completion:) method so that we can execute the same block of code as that of resetPositionAction. Go to the initializeWallMovement method and replace moveWallAction with the following code:

wall.runAction(moveWallAction, completion: { self.wall.position = CGPoint(x:(self.view!.bounds.size.width/2), y: self.view!.bounds.size.height + self.wall.frame.size.height/2) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required