그래서입니다. 대신 하위 클래스를 작성하여 다양한 글꼴 크기의 복수 SKLabelNodes
을 포함하는 사용자 정의 노드를 만들 수 있습니다. 예를 들어, scoreLabel은 다음 클래스의 인스턴스가 될 수 있습니다.
class ScoreLabel : SKNode
{
var label : SKLabelNode!
var scoreLabel : SKLabelNode!
var score : Int = 0 {
didSet
{
scoreLabel.text = "\(score)"
}
}
override init() {
super.init()
label = SKLabelNode(text: "Score : ")
label.position = CGPointMake(0, 0)
label.fontSize = 20
addChild(label)
scoreLabel = SKLabelNode(text: "\(0)")
scoreLabel.position = CGPointMake(label.frame.size.width , 0)
scoreLabel.fontSize = 25
addChild(scoreLabel)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
ScoreLabel
클래스 외부에서 단일 SKNode
로 ScoreLabel
행위에
let scoreLabel = ScoreLabel()
scoreLabel.position = CGPointMake(100, 300)
scoreLabel.score = 10
self.addChild(scoreLabel)
두 개의 레이블을 사용. SKActions
은 ScoreLabel
에서 실행될 수 있으며 child label nodes
에 모두 영향을 미칩니다. 예 :
scoreLabel.runAction(SKAction.scaleTo(2.0, duration: 2.0))
이렇게하면 두 레이블을 하나의 단위로 함께 표시합니다.
레이블 노드가 속성이 지정된 문자열을 지원하지 않습니까? – LearnCocos2D
그럴까요? 나는 그렇게 생각하지 않는다. NSAttributedString에서 문자열 텍스처를 수동으로 생성하는 것보다이 프로세스가 더 쉽다고 생각했습니다. – rakeshbs