0
我在创建的OSX游戏的didBeginContact里面的逻辑有些麻烦。这是写在迅速,这里是代码当前是:didBeginContact逻辑OSX swift
func didBeginContact(contact: SKPhysicsContact) {
let collision: UInt32 = contact.bodyA.categoryBitMask |
contact.bodyB.categoryBitMask
if collision == PhysicsCategory.player | PhysicsCategory.wall {
} else if collision ==
PhysicsCategory.player | PhysicsCategory.box {
player.setJump(true)
} else if collision ==
PhysicsCategory.player | PhysicsCategory.floor {
player.setJump(true)
}
if collision ==
PhysicsCategory.laser | PhysicsCategory.wall {
effects = SKEmitterNode(fileNamed: "Explosion.sks")
addChild(effects!)
laser!.removeFromParent()
}
else if collision ==
PhysicsCategory.laser | PhysicsCategory.floor {
effects = SKEmitterNode(fileNamed: "Explosion.sks")
addChild(effects!)
laser!.removeFromParent()
}
我觉得这混乱的if语句是效率极其低下,但我不知道如何将其转换为一个switch语句或者是否会甚至更有效率。我尝试删除'其他',只是有一系列的'如果'的声明,但当碰撞发生时,我还有更多的错误(盒子掉入墙壁等等。)任何建议将是令人满意的