iosanimationsprite-kitskspritenodeskemitternode

SpriteKit: how to make SKEmitterNode particles twinkle?


The SKEmitterNode in SpriteKit lets you change particle properties, but how can you animate the particles so they twinkle like at the 0:12 mark of this video?

https://www.youtube.com/watch?v=wYy2G0lVTAM

Is this possible?

We tried rapidly alternating the color from yellow to white (the sprite is white originally) but this doesn't achieve the desired twinkling effect:

        let colorizeYellow = SKAction.colorize(with: UIColor.yellow, colorBlendFactor: 1.0, duration: 0.2)
        let colorizeReset = SKAction.colorize(withColorBlendFactor: 0.0, duration: 0.2)
        let colorizeSequence = SKAction.sequence([colorizeYellow, colorizeReset])
        let colorizeRepeat = SKAction.repeatForever(colorizeSequence)

Solution

  • According to Apple's documentation, you can add actions to particles:

    This means you can perform other interesting tricks, such as animating the particle’s textures.

    In the video example you provided, most particles start at full "twinkle" and get smaller over time, until just a dot is left that quickly fades away. So start with a twinkle sprite (kind of like a plus sign with faded tips), scale it down and crossfade it with a plain dot that also fades out as it scales down. That should be very close to the effect in the video.