【发布时间】:2015-08-05 17:02:20
【问题描述】:
所以在我的游戏中,我真的想让生活指数更加动态,而不仅仅是一个倒计时的标签。我在屏幕顶部添加了三个精灵,如下所示:
它们被这段代码插入到一个 for 循环中:
// Add Life to player
var lifeIndexCount = 0
var positionAdd:CGFloat = 10.0
for lifeIndexCount in 0..<3 {
let lifeIndex = SKSpriteNode(imageNamed: "bullet.png")
lifeIndex.position = CGPoint(x: self.frame.size.width * -1.5, y: self.frame.size.height * 0.93)
let lifeIndexMove = SKAction.moveTo(CGPoint(x: (size.width * 0.05) + positionAdd, y: size.height * 0.93), duration: NSTimeInterval(0.7))
let lifeIndexRotation = SKAction.rotateByAngle(CGFloat(-2 * M_PI), duration: 0.3)
lifeIndex.runAction(SKAction.sequence([lifeIndexMove, lifeIndexRotation]))
addChild(lifeIndex)
positionAdd = positionAdd + 25.0
我想在玩家飞船错过一球后立即移除每一个。就像生命精灵旋转和获取屏幕的小动画一样。我已经设置了我的联系人代表,但我不知道如何抓取它们并制作动画,以便在发生失误时它们可以关闭。
func didBeginContact(contact: SKPhysicsContact) {
var contactBody1: SKPhysicsBody
var contactBody2: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
contactBody1 = contact.bodyA
contactBody2 = contact.bodyB
} else {
contactBody1 = contact.bodyB
contactBody2 = contact.bodyA
}
if ((contactBody1.categoryBitMask == 1) && (contactBody2.categoryBitMask == 2)) {
//Run when the bullet contacts the line
contactBody2.node!.removeFromParent()
// I WANT TO INSERT CODE HERE TO REMOVE A LIFE AT THE TOP
} else if ((contactBody1.categoryBitMask == 2) && (contactBody2.categoryBitMask == 4)) {
//Run when the bullet contacts the limbo
}
}
谢谢!
【问题讨论】:
标签: ios swift sprite-kit collision-detection