我已经获得了收集硬币的节点,但是当发生这种情况时我想要某种类型的动画。我如何添加" + 1"每次节点收集硬币时动画?我不知道是否应该使用SKAction,并且每次在节点和硬币之间发生接触时都会执行动作。
答案 0 :(得分:0)
是的,我是用SKAction做的(当您将此代码放入“更新”方法时,它会在您每次获得硬币时显示):
if CGRectIntersectsRect(player.frame, coin.frame) {
coins++ //your variable
let addCoinsLabel = SKLabelNode(fontNamed: "ChalkboardSE-Regular")
addCoinsLabel.text = "+1"
addCoinsLabel.fontSize = 40
addCoinsLabel.fontColor = UIColor.redColor()
addCoinsLabel.zPosition = 200
addCoinsLabel.position = CGPoint(x: CGRectGetMidX(self.frame), y: self.frame.size.height*0.7)
self.addChild(addCoinsLabel)
let actionLabelfadeIn = SKAction.fadeInWithDuration(0.5)
let actionLabelMove = SKAction.moveBy(CGVector(dx: 0.0, dy: 100), duration: 0.5)
let actionRemoveFromParent = SKAction.removeFromParent()
let sequence = SKAction.sequence([actionLabelfadeIn, actionLabelMove, actionLabelFadeOut, actionRemoveFromParent])
addCoinsLabel.runAction(sequence)
}