Updated for Xcode 9.3 and Swift 4.1. Learn how to make a Candy Crush-like mobile game, using Swift and SpriteKit to animate and build the logic of your game.
Thanks for the tutorial. I have a question about MVC here. If âCookieâ is a model, why does it have a reference to a SpritKitNode? Wouldnât that be like a CoreData model object having a reference to a UIView? I thought the M and V were supposed to stay decoupled via the C. I can see how it makes things convenient in this case though. Thanks
Youâre welcome. And thanks for the question â itâs a good one!
Each instance of the Cookie class includes a reference to its corresponding sprite name. So a croissant Cookie, for example, knows the name of the croissant sprite and highlighted croissant sprite.
But that doesnât affect anything on the screen. Itâs just a property of this croissant cookie (or data in the Model.)
Sprites are added to the scene via the addSprites() function GameScene.swift, which is part of the View.
Hello,
Thanks for tutorial.
Sadly i encounter this error: Value of type âGameSceneâ has no member âaddSpritesâ
This is happening when beginGame() is called.
Any help is apreciated.
I did notice that the CookieCrunchPart1-Final/CookieCrunch/GameScene.swift does not include the cropLayer and maskLayer which are implemented in the Making the Tiles Visible step.
So that error tells me the function âaddSprites()â is not found in your GameScene.swift. Take a look at the tutorial again and make sure you didnât accidentally skip this bit:
Hi @melcu: Are you running in the simulator or your phone? If your phone, check to make sure you specify a development team in Xcode. I get two errors when I try to run the Part 1 - Final project on my phone without setting a dev team:
Great tutorial. I believe there is a bug. If there are 2 vertical cookies in the last column, and you try to make a chain by moving a cookie from the same column (so moving it vertically, not horizontally from another column), it is an invalid swap, but it shouldnât be. Can you help with this?
Hi @c0nman: Are you trying to move a cookie across the gap? That is not allowed, so would rightly be an invalid swap. In the last column, there are a pair of three vertical slots (thereâs a gap, three vertical cookies, a gap, three vertical cookies, a gap), so I donât think it would be possible to make any vertical move that makes a vertical match. Am I misunderstanding you?
When you make vertical swap in last cols mechanic canât detect possible swap.
Need add some logic to Level.swift in detectPossibleSwaps()
Extend If add :
else if column == numColumns - 1, let cookie = cookies[column, row] {
if row < numRows - 1,
let other = cookies[column, row + 1] {
cookies[column, row] = other
cookies[column, row + 1] = cookie
// Is either cookie now part of a chain?
if hasChain(atColumn: column, row: row + 1) ||
hasChain(atColumn: column, row: row) {
set.insert(Swap(cookieA: cookie, cookieB: other))
}
// Swap them back
cookies[column, row] = cookie
cookies[column, row + 1] = other
}
}
after
if column < numColumns - 1,
let cookie = cookies[column, row]