0

所以这就是我的情况。

我有发射器从屏幕顶部产生并移动到屏幕底部,我试图让一个 png 图像跟随它们(用于命中检测目的)

问题是我需要实时更新 PNG 图像以跟踪 skemitternode,并且因为我正在生成发射器节点的多个实例,所以我无法将它们设为全局变量(需要为 n 个实例创建一个新的本地化集)

所以我想出的解决方案是有一个while循环,继续将PNG更新到发射器节点坐标。循环的条件是在粒子数小于 500(我设置的粒子寿命)时继续。

我无法让 png 图像与 skemitter 节点保持一致。它总是超过它或失去跟踪。

目前我正在使用:

while (particle < 5000) {
    enemySmoke.position = Enemy.position
    particle++
}

其中enemySmoke 是沿Y 轴移动的SKEmitter 节点

var action = SKAction.moveToY(SH-SH, duration: 10 - duration)
// Basically moving to bottom of screen faster with each spawn as I have 
// duration variable incrementing.

enemySmoke.runAction(SKAction.repeatActionForever(action))
Enemy.runAction(SKAction.repeatActionForever(action))

如何让发射器和 png 保持在彼此上?

4

1 回答 1

0

SKEmitterNode“跟随”一个SKSpriteNode,到目前为止,最简单的解决方案是将发射器作为您的孩子,SKSpriteNode并且只移动SKSpriteNode. 例如:

sprite.addChild(emitter)

目前发射的粒子将被添加到SKSpriteNode. 这不是一个想法行为,因为粒子会随着SKSpriteNode. 要解决此问题,您应该将targetNodeof设置SKEmitterNode为 be SKScene

emitter.targetNode = self // Assuming self is the SKScene.
于 2015-06-04T20:24:56.293 回答