我有一个关于我的发射器产卵的碰撞的问题。当冲突发生时,应用程序就会崩溃。但从我所做的研究来看,我看不出有什么问题。
冲突:
if bodyA.categoryBitMask == 1 && bodyB.categoryBitMask == 3 || bodyA.categoryBitMask == 3 && bodyB.categoryBitMask == 1{
print("END GAME")
let dieexplostionNode = SKEmitterNode(fileNamed: "Explode")
player.addChild(dieexplostionNode!)
}
我是不是遗漏了什么让发射器产卵的东西?每次碰撞时,它都会崩溃。
发布于 2017-07-10 19:37:56
基于你对上面答案的评论,我认为Action是你所需要的。
if bodyA.categoryBitMask == 1 && bodyB.categoryBitMask == 3 || bodyA.categoryBitMask == 3 && bodyB.categoryBitMask == 1{
print("END GAME")
dieexplostionNode = SKEmitterNode(fileNamed: "Explosion.sks"){
dieexplostionNode.targetNode = self
//dieexplostionNode.position = player.position - no need for this!
// add 3 actions
let wait = SKAction.wait(forDuration: 2)
let addExplosion = SKAction.run {
self.player.addChild(dieexplostionNode!)
}
let removeExplosion = SKAction.run {
dieexplostionNode?.removeFromParent()
}
// put them in a sequence.
let seq = SKAction.sequence([addExplosion,wait,removeExplosion])
// run the sequence
self.run(seq)
}
这会将dieexplostionNode添加到播放器中。然后等待2秒钟。然后删除dieexplostionNode
发布于 2017-07-10 18:23:50
你是不是把SceneKit和SpriteKit搞混了?如果要添加SpriteKit粒子发射器文件,请在SceneKit中使用SCN文件/缩写。文件->新的-> IOS/OSX ->资源-> SpriteKit粒子文件
https://stackoverflow.com/questions/45003464
复制相似问题