Last active
March 1, 2023 02:32
-
-
Save smks/e88600375c01a50a0056 to your computer and use it in GitHub Desktop.
Haxeflixel Confetti Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.particles; | |
import flixel.effects.particles.FlxEmitter; | |
import flixel.effects.particles.FlxParticle; | |
import flixel.FlxG; | |
import flixel.group.FlxTypedGroup; | |
import flixel.system.FlxCollisionType; | |
import flixel.util.FlxRandom; | |
/** | |
* @author Shaun Stone (SMKS) <http://www.smks.co.uk> | |
*/ | |
class Confetti extends FlxTypedGroup<FlxEmitter> | |
{ | |
#if mobile | |
private static inline var MAX_COUNT:Int = 30; | |
#else | |
private static inline var MAX_COUNT:Int = 100; | |
#end | |
var emitter:FlxEmitter; | |
public function new() | |
{ | |
super(MAX_COUNT); | |
emitter = new FlxEmitter(0, 0, MAX_COUNT); | |
emitter.acceleration.y = 200; | |
emitter.gravity = 150; | |
for (i in 0...MAX_COUNT) { | |
var p = new ConfettiParticle(); | |
emitter.add(p); | |
emitter.kill(); | |
} | |
emitter.setSize(FlxG.width, 0); | |
add(emitter); | |
} | |
override public function update():Void | |
{ | |
super.update(); | |
} | |
public function trigger():Void | |
{ | |
for (i in 0...MAX_COUNT) { | |
emitter.recycle(FlxParticle); | |
} | |
emitter.start(true, 0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.particles; | |
import flixel.effects.particles.FlxParticle; | |
import flixel.FlxG; | |
import flixel.interfaces.IFlxParticle; | |
import flixel.util.FlxRandom; | |
/** | |
* @author Shaun Stone (SMKS) <http://www.smks.co.uk> | |
*/ | |
class ConfettiParticle extends FlxParticle implements IFlxParticle | |
{ | |
var spinRotation:Float; | |
public function new() | |
{ | |
super(); | |
this.makeGraphic(20, 20, FlxRandom.color()); | |
this.x = FlxRandom.floatRanged(0, FlxG.width - this.width); | |
this.y = this.height * 1.5; | |
this.exists = false; | |
this.angularVelocity = 0.1; | |
this.friction = 0; | |
this.spinRotation = FlxRandom.floatRanged(0.01, 0.05); | |
} | |
override public function update():Void | |
{ | |
super.update(); | |
this.scale.x = 1; | |
this.scale.y = this.scale.y - spinRotation; | |
if (this.scale.y <= -1) { | |
this.scale.y = 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment