I would like to merge an SKShapeNode and an SKLabeNode to make only one node
Here is my "Bloque" class who drawn an rectangle and add a sklabelnode child on it:
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")
}
}
With that code, when i click on the colored space it work but if the user click on the number it doesn't work. It seem like the the SKShapeNode and the SKlabelNode are not one entire node
Here is the touchesBegan Function :
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")
}
}
}
I would like to know how i can merge the both SKNode to make juste one, so when the user click on the colored zone or into the number it work. Can someone help me ? Sorry for my bad english :/