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 2

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/1118-how-to-make-a-game-like-candy-crush-with-spritekit-and-swift-part-2

Another great tutorial filled with good stuff! Moving on to the third one right now!

I am a little confused by the use of private when referring to a property. Your instructions asks for a private property but does not use the private keyword and vise versa. Can you clarify the use?

Example
Go to GameScene.swift and add two private properties to the class:
var swipeFromColumn: Int?
var swipeFromRow: Int?

In Level.swift, add a new property:
private var possibleSwaps = Set<Swap>()

Thanks

Hey :] Nicely spotted! This is a typo and I’ll fix it straight away – the properties should be private :]

'Add Sound Efffects ’ – Efffects -> Effects

I’ve been implementing this step-by-step in Swift 2.3. You listed output at one point as:

possible swaps: [
swap type:SugarCookie square:(6,5) with type:Cupcake square:(7,5): true,
swap type:Croissant square:(3,3) with type:Macaroon square:(4,3): true,
swap type:Danish square:(6,0) with type:Macaroon square:(6,1): true,
swap type:Cupcake square:(6,4) with type:SugarCookie square:(6,5): true,
swap type:Croissant square:(4,2) with type:Macaroon square:(4,3): true,

However, I have not been able to find in the code how you outputted the “true” anywhere. I even downloaded your code at this stage, but unless I’m going blind, I don’t see it.

Thanks for this tutorial, by the way (and thanks to the original blogger as well). Learning a lot!

Hey @azcoder :] Thanks for your comment. You’re right – the true should be removed from the output. I’ll fix it straight away. Hope you’ll enjoy the rest of the series. Also note that the tutorial series was updated for Swift 3 (just in case you’re still using 2.3) :]

Thanks, Morten! Yes, I haven’t migrated my environment to Swift 3 yet, so I’ve been revising your code for Swift 2.3 compatibility. This is helping me see what changes I’ll need to be aware of when I do change over. :grinning:

Sounds good :] Let me know if you need the Swift 2 version for any of the parts – I still have that stored locally from before I updated the series to Swift 3.

Great tutorial! I am having an issue in the touchesMoved method. It is telling me that locationInNode has been renamed to location(in:), and then right below that where I declare (success, column, row) = convertPoint(location), I get the error Argument labels ‘(_:)’ do not match any available overloads.

@bush that is something that changed in Swift 3.0.1!
You can easily click on the first error and then on “fix it”. Swift will change it to Swift 3.0.1 syntax.

The “Argument labels” error can be fixed by replacing convertPoint(location) with convertPoint(point: location).

By the way, this tutorial is really great! Thanks a lot!

The complete function:

override func touchesMoved(_ touches: Set, with event: UIEvent?) {
guard swipeFromColumn != nil else { return }

    guard let touch = touches.first else { return }
    let location = touch.location(in: cookiesLayer)
    
    let (success, column, row) = convertPoint(point: location)
    if success {
        
        var horzDelta = 0, vertDelta = 0
        if column < swipeFromColumn! {          // swipe left
            horzDelta = -1
        } else if column > swipeFromColumn! {   // swipe right
            horzDelta = 1
        } else if row < swipeFromRow! {         // swipe down
            vertDelta = -1
        } else if row > swipeFromRow! {         // swipe up
            vertDelta = 1
        }
        
        if horzDelta != 0 || vertDelta != 0 {
            trySwap(horizontal: horzDelta, vertical: vertDelta)
            
            swipeFromColumn = nil
        }
    }
}

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! :]