Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make confetti?

I essentially want to emit confetti particles. Each particle is the same shape, however, I want each particle to be a random colour from a selection of colors I specify.

Is there a way for each emitted particle to have a random color or do I need a separate emitter for each particle color?

like image 934
asdfg Avatar asked Jun 25 '15 22:06

asdfg


People also ask

What material can I use to make confetti?

Choose paper or cardstock for the most color variety. Purchase paper in any weight or color you like. For simple confetti, use white printer paper or use multicolored paper if you'd like a burst of color. For a simple way to make unique confetti, purchase origami paper that has designs or patterns printed on them.

How do you make eco friendly confetti?

Alternatively you can use leaves from yours and your family's gardens. Simply dry them out and then use a hole punch to create circular confetti or a heart stamp to create heart shapes! These don't last forever but will last for a week at least.


1 Answers

You can use single emitter to achieve what you want:

import SpriteKit


class GameScene: SKScene, SKPhysicsContactDelegate {



    let emitter = SKEmitterNode(fileNamed: "particle")
    let colors = [SKColor.whiteColor(),SKColor.grayColor(),SKColor.greenColor(),SKColor.redColor(),SKColor.blackColor()]


    override func didMoveToView(view: SKView) {


        self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)


        emitter.position = CGPoint(x: 200, y:300)

        emitter.particleColorSequence = nil
        emitter.particleColorBlendFactor = 1.0

        self.addChild(emitter)

        let action = SKAction.runBlock({
            [unowned self] in
            let random = Int(arc4random_uniform(UInt32(self.colors.count)))

            self.emitter.particleColor = self.colors[random];
            println(random)
        })

        let wait = SKAction.waitForDuration(0.1)

        self.runAction(SKAction.repeatActionForever( SKAction.sequence([action,wait])))


    }

}

EDIT:

Try changing duration of wait action to get different results.

You can play with color ramp too (in particle editor) to achieve the same effect:

enter image description here

Or you can use particleColorSequence and SKKeyframeSequence in order to change particle color over its lifetime. Hope this helps.

like image 75
Whirlwind Avatar answered Oct 05 '22 02:10

Whirlwind