私はこれまで動作しているようだ別のアプローチがあります。
//あなたはターンを取らなければならない場合は、黒のディスクを持つforループwhitediskを繰り返すことができます。私は、選択された正方形の識別するために、.nameのを使用しています
func drawBoard() {
let numRows = 8
let numCols = 8
let x = scene?.size.width
xOffset = ((x)! - ((x)!/9) * CGFloat(numCols))
squareSize = CGSizeMake(x!/9, x!/9)
diskSize = CGSizeMake(x!/11, x!/11)
// Draw the squares
for row in 0...numRows-1 {
for col in 0...numCols-1 {
square = SKSpriteNode(texture: SKTexture(imageNamed: "square.png"), size: squareSize!)
//row and column both start with zero, may want to start with 1 later
square!.name = "square \(col)-\(row)"
square!.userInteractionEnabled = false
square!.position = CGPointMake(CGFloat(col) * squareSize!.width + xOffset, CGFloat(row) * squareSize!.height + xOffset)
self.addChild(square!)
}
}
// Draw the White disks "hidden"
for row in 0...numRows-1 {
for col in 0...numCols-1 {
let gamePiece = SKSpriteNode(texture: SKTexture(imageNamed: "whitedisk.png"), size: diskSize!)
gamePiece.name = "whitedisk \(col)-\(row)"
gamePiece.userInteractionEnabled = false
//print("Disk Name: \(gamePiece.name)")
gamePiece.position = CGPointMake(CGFloat(col) * squareSize!.width + xOffset, CGFloat(row) * squareSize!.height + xOffset)
gamePiece.hidden = true
self.addChild(gamePiece)
}
}
}
//ディスク変数は、そのターン、それは あるこの関数は、正方形が選択されたかを決定した後、ゲームの駒を表示するに応じて、whitediskかblackdiskのいずれかである
func placeDisk(name: String, disk: String) {
var myName = name
let theDisk = disk
myName = myName.stringByReplacingOccurrencesOfString("square", withString: theDisk)
let node = self.childNodeWithName(myName)
//print("Display: \(myName) - Node: \(String(node))")
node?.hidden = false
}
//私はtouchesEND機能をoverodeいますが、タッチを使用することができますがあなたのアイデアを再考する必要があるように思え
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let positionInScene = touch.locationInNode(self)
let name = self.nodeAtPoint(positionInScene).name
if name != nil {
print("Touched: \(name)")
placeDisk(name!, disk: "whitedisk")
}
}
}
も始めました。ユーザーは、隠された何かを押すことを彼は知っていると思われますか? – pingul
隠しtry alphaを使用する代わりに? – hamobi
ノードのalphaプロパティを0.0 –