Undead-Earth .com
Undead-Earth .com

Reputation: 81

SKAction Updating Last Instantiated Sprite Only

teaching myself spritekit while recouping from back surgery. Any help or instruction you may provide is greatly appreciated.

I have a function that adds a "monster" sprite with a child SKEmitter. I would like to update this emitter to "turn on" and "turn off" the SKEmitter. This functions as long as there is only a single sprite on the screen. The moment a second node is created from the function, the first one stops turning on and off.

It appears to me that the SKAction is only acting on the latest node. I just can't anything that would tell me how to fix this.

Example of what I see in the UI. SKEmitter On and Off

My code:

    flameThrowerSplash = SKEmitterNode(fileNamed: "flamesThrowerSplash.sks")!
    let newX = flameThrowerSplash.position.x - 475
    let newY = flameThrowerSplash.position.y + (zombie1.size.height * 0.7)
    let newLocation = CGPointMake(newX, newY)

    flameThrowerSplash.position = newLocation
    flameThrowerSplash.targetNode = currentScene

    let wait = SKAction.waitForDuration(0.5)
    let pauseEmitter = SKAction.runBlock({self.flameThrowerSplash.particleBirthRate = 0})
    let startEmitter = SKAction.runBlock({ self.flameThrowerSplash.particleBirthRate = 455})
    let wait2 = SKAction.waitForDuration(0.5)
    let run = SKAction.sequence([wait, startEmitter,wait2, pauseEmitter])

    zombie1.runAction(SKAction.repeatActionForever(run))

Upvotes: 1

Views: 45

Answers (1)

hamobi
hamobi

Reputation: 8130

it doesnt look like you want flameThrowerSplash to be a scene property.

instead of this

flameThrowerSplash = SKEmitterNode(fileNamed: "flamesThrowerSplash.sks")!

just declare it as a new variable

let flameThrowerSplash = SKEmitterNode(fileNamed: "flamesThrowerSplash.sks")

then you can add it to each zombie independently.

you were reassigning it for each new zombie.. thats why it was disappearing.

Upvotes: 2

Related Questions