Hello
Just to give a little context, I am trying to make a Mancala game in ios. I created the UI in the GameScene.sks file.
xCode Screenshot
I have each SKNode pit (pit0 is the bottom left pit and are numbered counter-clockwise from there)numbered with another SKNode inside of it called chips, which contains all the chip SKSpriteNodes for that pit. I am trying to make it so that when one of the pits is pressed all the chips move 4 pits over.
class GameScene: SKScene {
var touchLocation = CGPoint()
var gameBoard = SKNode()
var pits: Array<Pit> = Array(repeating: Pit(), count: 14)
override func sceneDidLoad() {
setUpGameBoard()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
touchLocation = touch.location(in: gameBoard)
let currentPit: Pit = ((gameBoard.atPoint(touchLocation).parent?.parent) ?? pits[0]) as! Pit
print(currentPit)
for i in 0..<14 {
if currentPit == pits[i] {
let move1 = SKAction.move(to: pits[i+1].position, duration: 0.5)
let move2 = SKAction.move(to: pits[i+2].position, duration: 0.5)
let move3 = SKAction.move(to: pits[i+3].position, duration: 0.5)
let move4 = SKAction.move(to: pits[i+4].position, duration: 0.5)
let waitAction = SKAction.wait(forDuration: 0.1)
let moveSequence = SKAction.sequence([move1, waitAction, move2, waitAction, move3, waitAction, move4])
currentPit.chipsNode.run(moveSequence)
}
}
}
}
func setUpGameBoard() {
gameBoard = childNode(withName: "gameBoard")!
for i in 0..<14 {
pits[i] = (childNode(withName: "gameBoard")?.childNode(withName: "pit\(i)"))! as! Pit
pits[i].chipsNode = pits[i].childNode(withName: "chips")!
pits[i].chips = pits[i].childNode(withName: "chips")?.children as! [Chip]
}
print(pits)
}
This code moves the chips but only moves them slightly not to the position where they are supposed to go. I am trying to move the chips SKNode containing all of the chips 4 pits counter-clockwise. Please help me if you can and if you are confused by what I am trying to do comment on this.