Spritekit Particle Emitter Multi Image

SpriteKit particle emitter change color

This hardly counts as an answer but I couldn't fit it all into a comment so...please bear with me.

The good news is that your code seems to work!

I tried creating a new Sprite Kit project and pasted your code into that so I ended up with a GameScene class of type SKScene looking like this:

import SpriteKit
import GameplayKit

class GameScene: SKScene {

let emitter = SKEmitterNode(fileNamed: "squares.sks")
let colors = [SKColor.red, SKColor.green, SKColor.blue]
var lastUpdateTime: TimeInterval?

override func didMove(to view: SKView) {
emitter?.particleColorBlendFactor = 1.0
emitter?.particleColorSequence = nil
addChild(emitter!)
}

override func update(_ currentTime: TimeInterval) {
var delta = TimeInterval()
if let last = lastUpdateTime {
delta = currentTime - last
} else {
delta = currentTime
}
if delta > 1.0 {
lastUpdateTime = currentTime
let random = Int(arc4random_uniform(UInt32(self.colors.count)))
emitter?.particleColor = colors[random]
}
}
}

And then I created a new SKEmitterNode from the template (I used fire...just to chose something) and named it squares.sks.

When I run that, I can see this:

Sample Image

So...where does that leave us?

I'm thinking there must be something different in your setup.
If you try to create a new example project like mine, are you able to get it to work?

Yeah...hardly an answer I know, but think of it as a reassurance that you are on the right path at least :)

Sprite Kit Particle Emitter Shape

Only a SKTexture can be used, but that doesn't stop you from using SKShapeNode to create shapes and then create a SKTexture of that shape via the SKView method textureFromNode:.

Making a particle follow a path in spriteKit

You sent the particle emitter to follow the path. If you want individual particles to run an action, use the emitter's particleAction property:

myParticle.particleAction = forever;


Related Topics



Leave a reply



Submit