【发布时间】:2015-08-04 02:43:32
【问题描述】:
我正在构建我的第一个 swift 游戏,但我在为玩家实现生活时遇到了困难。它应该在不同的屏幕位置显示三个生命,就像一个微型图像......我知道 for 循环可以完成这项工作,但我不知道如何编写它。当我尝试使用 addChild(LifeIndex) 将相同的精灵添加到屏幕时,它会引发错误。
下面是代码:
// Add Life to player
let lifeIndex = SKSpriteNode(imageNamed: "bullet.png")
var lifeCount = 3
lifeIndex.position = CGPoint(x: self.frame.size.width * -1.5, y: self.frame.size.height * 0.1)
let lifeIndexMove = SKAction.moveTo(CGPoint(x: size.width * 0.1, y: size.height * 0.1), duration: NSTimeInterval(0.7))
let lifeIndexRotation = SKAction.rotateByAngle(CGFloat(-2 * M_PI), duration: 0.3)
addChild(lifeIndex)
lifeIndex.runAction(SKAction.sequence([lifeIndexMove, lifeIndexRotation]))
我怎样才能做到三遍?另外,我需要将不同的点放入 moveTo 中,以便它们可以并排,而不是彼此重叠。
【问题讨论】:
-
将所有这些放在循环 lifeCount 次数的 for 循环中。 lifeIndexMove 和 lifeIndexRotation 对于这三个都一样吗?
-
lifeIndexRotation 将是相同的,但我需要在 lifeIndexMove 的 x 参数中增加一个增量,以便它可以与其他精灵并排。
标签: swift sprite-kit