首先是字体:
这段代码可以打印出系统支持的所有字体名,并设置字体为Zapfino
let lableOfMenu = SKLabelNode(text: "welcome to YellowMoon!")
for familyName in UIFont.familyNames() as [String]{
for fontName in UIFont.fontNamesForFamilyName(familyName) as [String]{
print (fontName)
}
}
lableOfMenu.fontSize = 20
lableOfMenu.fontName = "Zapfino"
lableOfMenu.fontColor = UIColor.whiteColor()
//对齐方式
lableOfMenu.verticalAlignmentMode = .Top
lableOfMenu.horizontalAlignmentMode = .Left
lableOfMenu.position = CGPoint(x: size.width/2.0,y: size.height/2.0)
self.addChild(lableOfMenu)
下面来说动画咯:
spriteKit中的动画是使用SKAction类完成的,它代表着节点状态的变化。
SKAction代表移动,旋转,颜色变化等等。重要的是,操作随着时间的推移而发生,可以排列为序列和组。
let moveAction = SKAction.moveBy(CGVector(dx: 0,dy: 50),duration: 0.5)
let moveBackJustPlayYou = moveAction.reversedAction()
let rotateAction = SKAction.rotateByAngle(CGFloat(M_PI),duration: 1)
let scaleAction = SKAction.scaleTo(0.5,duration: 1)
let rotateWhileScaling = SKAction.group([rotateAction,scaleAction]) let rotateThenScaling = SKAction.sequence([rotateAction,scaleAction]) lableOfMenu.runAction(rotateThenScaling) lableOfMenu.runAction(rotateWhileScaling)
注:group方法是让两种动作同时执行,而sequence则是依次执行。