Group Group Group Group Group Group Group Group Group
raywenderlich.com Forums

How to Make a Game Like Candy Crush with SpriteKit and Swift: Part 3

In this epic tutorial you'll learn how to make a tasty match-3 game like Candy Crush with SpriteKit and Swift. Now updated for Xcode 7.3 and Swift 2.2.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1117-how-to-make-a-game-like-candy-crush-with-spritekit-and-swift-part-3

Is it possible to remove same type neighbour cookies as in below illustrated.
if yes then how?

Hi @mfaarkrog,
I think this tutorial is really amazing and helpful!
But why do I get the error: "Extra argument ‘completion’ in call?

scene.animate(swap: swap, completion: handleMatches) //Error: Extra argument ‘completion’ in call

I figured out that since Swift 3.0.1 it have to be “scene.animate(swap, completion: handleMatches”), but the error is still there. It‘s driving me crazy. I try to get it to work since two hours.

Please help me! :]

Hi @liberatordg,
I ran into the same issue as I was walking through the tutorial, and you are correct about the Swift 3.0.1 change. However, I think your statements may be a little jumbled as mine were indeed in the wrong spot according to the part 3 finished sample. The handleMatches() function should look as follows:

func handleMatches() {
let chains = level.removeMatches()
if chains.count == 0 {
beginNextTurn()
return
}
scene.animateMatchedCookies(for: chains) {
let columns = self.level.fillHoles()
self.scene.animateFallingCookiesFor(columns: columns) {
let columns = self.level.topUpCookies()
self.scene.animateNewCookies(columns) {
self.view.isUserInteractionEnabled = true
}
}
}
}

Happy Coding!

Hi @badluckbryce,
I think you’re right.

Thanks a lot!

@badluckbryce,

I tried your changes but i still get the error messages…
What am I doing wrong?

i have my code now like this:

func handleSwipe(_ swap: Swap) {
view.isUserInteractionEnabled = false

    if level.isPossibleSwap(swap) {
        level.performSwap(swap: swap)
        scene.animate(swap){
          self.handleMatches()
        }
    } else {
        scene.animateInvalidSwap(swap) {
            self.view.isUserInteractionEnabled = true
        }
    }
}

Now i don’t have the error, but the game does not work well. 'Cause if I can make an match of 3, he thinks it isn’t a match. And sometimes when the new cookies are falling down he doesn’t check if there is a match of 3. Does anyone have this? Or does anyone know how to solve this?

To fix the original error, all I did was change the call of scene.animate(swap) to:

scene.animate(swap, completion: {
            self.handleMatches()
            self.view.isUserInteractionEnabled = true
})

This is just a different closure syntax that avoids the error and makes the game work as intended.

Hi @mfaarkrog,

I am running into an issue with the final version of the game. When performing a swap of two cookies, if the user were to swipe on the screen while the two cookies are in the middle of their swap animation, often the cookies will perform another swap and have their new position be where the cookie they are swapping with was in the middle of their animation, i.e. off the grid that we have effectively created. I was curious if you ran into this issue/found a way to resolve it. Thanks.

David

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]