Swift version: 5.10
SpriteKit has built-in support for particle systems, which are a realistic and fast way to create effects such as smoke, fire and snow. Even better, Xcode has a built-in visual particle editor so that you can tweak your designs until they look exactly right.
To get started, right-click on your project in Xcode and choose New File. Select iOS > Resource > SpriteKit Particle File, then choose the Smoke template and click Next to name your effect. Once that's done, your particle will be opened immediately in the visual editor so you can adjust its design.
When it comes to using your effect, just create a new SKEmitterNode
object using the name of your particle effect, like this:
if let particles = SKEmitterNode(fileNamed: "yourParticleFile.sks") {
particles.position = player.position
addChild(particles)
}
Obviously you will want to set your own position rather than using an example player
node.
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Available from iOS 7.0 – see Hacking with Swift tutorial 11
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.