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:
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
Implicit Cast Function Receiving Tuple
Nsdateformatter Detect 24-Hour Clock in Os X and iOS
Why Do I Get "Static Member '...' Cannot Be Used on Instance of Type '...'" Error
Swift Conditional Conformances with Generic Type
Nswindow with Round Corners in Swift
Drawing Pixels on the Screen Using Coregraphics in Swift
How to Prevent a Spacer to Make a VStack Greedly Grow Beyond Necessary
Swift: Visual Glitches When Presenting a Main and Alternative (Login/Onboarding) Flow
How to Get Distinct Results from a Single Field in Core Data (Swift 4)
Cloudkit Ckqueryoperation Doesn't Get All Records
Swiftui, Shadow Only for Container
Is This Safe to Call Wait() of Dispatchsemaphore Several Times at One Time
How to Retrieve All Contacts Using Cncontact.Predicateforcontacts
Deleting a Camera Roll Asset Using Photos Framework