-
Notifications
You must be signed in to change notification settings - Fork 123
/
ConfettiParticle.as
70 lines (54 loc) · 1.96 KB
/
ConfettiParticle.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.grapefrukt.games.juicy.effects.particles {
import com.grapefrukt.display.utilities.ColorConverter;
import com.grapefrukt.games.general.particles.Particle;
import com.gskinner.geom.ColorMatrix;
import com.gskinner.motion.easing.Back;
import com.gskinner.motion.easing.Bounce;
import com.gskinner.motion.easing.Exponential;
import com.gskinner.motion.GTween;
import flash.filters.ColorMatrixFilter;
import flash.geom.ColorTransform;
/**
* ...
* @author Martin Jonasson, m@grapefrukt.com
*/
public class ConfettiParticle extends Particle {
private var _gfx:ConfettiParticleGfx;
private var _vectorX:Number;
private var _vectorY:Number;
private var _age:Number;
public function ConfettiParticle(lifespan:Number=2) {
super(lifespan);
_gfx = new ConfettiParticleGfx;
addChild(_gfx);
_gfx.rotation = Math.random() * 360;
_gtween.onChange = update;
var colors:Array = ColorConverter.HSBtoRGB(Math.random(), 1, 1);
_gfx.transform.colorTransform = new ColorTransform(colors[0] / 255, colors[1] / 255, colors[2] / 255);
}
override public function init(xPos:Number, yPos:Number, vectorX:Number = 0, vectorY:Number = 0):void {
_vectorY = vectorY;
_vectorX = vectorX;
x = xPos;
y = yPos;
rotation = 0;
scale = .8;
alpha = 1;
_gtween.delay = Math.random() * .3;
_gtween.proxy.scaleX = _gtween.proxy.scaleY = .01;
_gtween.proxy.rotation = Math.random() * 360;
//_gtween.proxy.alpha = 0;
_age = Math.random() * _gfx.totalFrames;
}
private function update(gt:GTween):void {
var timeDelta:Number = GTween.timeScaleAll;
_age += timeDelta;
_gfx.gotoAndPlay(1 + (int(_age) % _gfx.totalFrames - 1));
x += _vectorX / 100 * timeDelta;
y += _vectorY / 100 * timeDelta;
_vectorY += 10 * timeDelta;
_vectorX -= _vectorX * .05 * timeDelta;
_vectorY -= _vectorY * .05 * timeDelta;
}
}
}