How To Make a Game Like Cut the Rope With SpriteKit

In this tutorial, you’ll learn how to build a game like Cut the Rope with SpriteKit in Swift, complete with animations, sound effects and physics! By Brody Eller.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Getting Rid of an Awkward Sound Effect

Did you discover a bug? If you miss the croc, the splashing sound plays multiple times. This is because you trigger "level complete" logic repeatedly before the game transitions to the next scene. To correct this, add a new state property to the top of the class:

private var isLevelOver = false

Now modify update(_:) and didBegin(_:) by adding the following code at the top of each of them:

if isLevelOver {
  return
}

Finally, inside the other if statements of the same methods, add some code to set the isLevelOver state to true:

isLevelOver = true

Now, as soon as the game detects that isLevelOver is set, either because the pineapple hit the ground or because the croc got its meal, it'll stop checking for the game win/lose scenarios. It won't keep repeatedly trying to play those sound effects.

Build and run. There are no awkward sound effects anymore!

FeedingTime

Adding Some Difficulty

After playing a few rounds, the game seems a bit too easy. You'll quickly get to the point where you can feed the croc with a single well-timed slice through the three vines.

Make things trickier by using the value in Constants.swift, CanCutMultipleVinesAtOnce.

In GameScene.swift, add one last property at the top of the GameScene class definition:

private var didCutVine = false

Now locate checkIfVineCut(withBody:) and add the following if statement at the top:

if didCutVine && !GameConfiguration.canCutMultipleVinesAtOnce {
  return
}

Add this code to the bottom of the same method, inside the if statement:

didCutVine = true

Just to keep things together, find the touchesBegan(_:with:), and add the following line:

didCutVine = false

This way, you reset didCutVine whenever the user touches the screen.

Build and run again.

Cut the rope with SpriteKit only cut once

You should see that it's now only possible to snip one vine each time you swipe. To cut another, you have to lift your finger and then swipe again.

Where to Go From Here?

You can download the completed version of the project using the Download Materials button at the top or bottom of this Cut The Rope with SpriteKit tutorial.

Don't stop now! Try adding new levels, different vines and maybe even a score display and timer.

If you’d like to learn more about SpriteKit, be sure to check out our book, 2D Apple Games by Tutorials.

If you have any questions or comments, feel free to join in the discussion below!

Brody Eller

Contributors

Brody Eller

Author

Bas Broek

Tech Editor

Sandra Grauschopf

Editor

Aleksandra Kizevska

Illustrator

Marin Bencevic

Final Pass Editor

Richard Critz

Team Lead

Over 300 content creators. Join our team.