this is how i put my emitter:
func addParticle(at: CGPoint) {
let emitter = SKEmitterNode(fileNamed: "hit.sks")
emitter?.position = at
emitter?.zPosition = 10
scene.addChild(emitter!)
scene.run(SKAction.wait(forDuration: 1), completion: {
emitter?.removeFromParent()
})
}
and sometimes i have a performance lag, time profiler shows me that i am having sks file delay (file decoding etc). is there any way i can avoid this?
You're not actually preloading the particle system. You're creating a new one, each time, and removing it (and causing there to be no reference to it) at the end, so it gets GC'd.
Instead, add the particle system to a node that's offscreen, and when you need it, move it back into the scene, where you need/want it, then move it back offscreen when you no longer need it.
This will prevent any need to create a particle system, wind it up and get it running, etc.
You'll just need to play and pause it... and move it.
You can pause a particle system directly, or by pausing its parent node, so it's ready at a state you want it to be in when you bring it back onscreen.
Read about more of this here: https://developer.apple.com/documentation/spritekit/skemitternode/1398027-advancesimulationtime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With