我想合併的SKShapeNode和SKLabeNode僅做一個節點合併SKShapeNode和SKLabelNode
這裏是我的「BLOQUE」類誰繪製一個矩形,並添加sklabelnode孩子就可以了:
class Bloque : SKShapeNode
{
var color : String!
var numero : Int!
var type : Int!
var labelNumeroBloque : SKLabelNode!
init(type : Int, numero : Int, tailleBloque : CGSize)
{
super.init()
self.numero = numero
self.type = type
switch (type)
{
case 0: color = "#4aaddb"
default: color = "#ccc"
}
var rect = CGRect(origin: CGPoint(x: 0.5, y: 0.5), size: CGSize(width: tailleBloque.width, height: tailleBloque.height))
self.path = CGPathCreateWithRoundedRect(rect, 2.0, 2.0, nil)
self.fillColor = UIColor(rgba: color)
self.name = "\(numero)"
self.lineWidth = 0.0
self.zPosition = 200
labelNumeroBloque = SKLabelNode(text: String(numero))
labelNumeroBloque.position = CGPointMake(tailleBloque.width/2, tailleBloque.height/2)
labelNumeroBloque.verticalAlignmentMode = .Center
labelNumeroBloque.horizontalAlignmentMode = .Center
labelNumeroBloque.fontName = "ArialMT"
labelNumeroBloque.fontSize = 20
labelNumeroBloque.name = "\(numero)"
self.addChild(labelNumeroBloque)
}
required init?(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
}
有了這段代碼,當我點擊彩色空間它的工作,但如果用戶點擊數字它不起作用。 它看起來像的SKShapeNode和SKlabelNode不是一個完整的節點
這裏是的touchesBegan功能:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
for touch in (touches as! Set<UITouch>)
{
let location = touch.locationInNode(self)
let cliqueNode = nodeAtPoint(location)
if let bloque = cliqueNode as? Bloque
{ // verifie que le bloque est du type Bloque
nb++
bloque.removeFromParent()
}
else
{ // mauvais bloque cliqué
println("Debug : mauvais bloque")
}
}
}
我想知道我怎麼能既SKNode合併做一個合理的,所以當用戶點擊彩色區域或數字它的工作。 有人可以幫我嗎? 對不起,我的英語不好:/
謝謝,它的工作:D – Xakaa