-
Notifications
You must be signed in to change notification settings - Fork 3
/
SparkSFX.js
57 lines (48 loc) · 1.37 KB
/
SparkSFX.js
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
var SparkSFX = (function () {
var LIFE_TIME = .12;
var WIDTH = 28;
var HEIGHT = 24;
function SparkSFX () {
this.imperviousToShootingRay = false;
this.inUse = false;
this.lifeTime = 0;
this.spriteImg = resources.get('player');
this.animations = [];
this.initAnimations();
};
SparkSFX.prototype = new BasicObject();
SparkSFX.prototype.update = function (dt) {
this.lifeTime += dt;
if(this.lifeTime >= LIFE_TIME) {
this.inUse = false;
this.lifeTime = 0;
}
};
SparkSFX.prototype.spawn = function (x, y) {
this.x = x - WIDTH * .5;
this.y = y - HEIGHT * .5;
this.inUse = true;
this.lifeTime = 0;
};
SparkSFX.prototype.render = function (viewportContext) {
var animation = this.animations[0];
if(animation) {
animation.render(viewportContext, Math.floor(this.x), Math.floor(this.y));
}
};
SparkSFX.prototype.initAnimations = function () {
this.animations[0] = (new Sprite({
img: this.spriteImg,
origins: [
{
x: 2510
}
],
width: WIDTH,
height: HEIGHT,
frames: 1,
animSpeed: 60
}));
};
return SparkSFX;
})();