-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite.js
34 lines (32 loc) · 985 Bytes
/
sprite.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
var s_pipe;
function Sprite(img, x, y, width, height) {
this.img = img,
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
Sprite.prototype.draw = function(ctx, x, y, rotation, fc, mY, filled){
var X = x*(fc*100);
var Y = y*(fc*100)+mY;
if(filled){
ctx.globalAlpha=0.2;
ctx.fillRect(X,Y,this.width*fc,this.height*fc);
ctx.globalAlpha=1;
}
ctx.save();
ctx.translate(X+this.width*fc/2,Y+this.height*fc/2)
ctx.rotate(rotation*Math.PI/180);
ctx.drawImage(this.img, this.x, this.y, this.width, this.height, -(this.width*fc/2), -(this.height*fc/2), this.width*fc, this.height*fc);
ctx.restore();
}
function initSprites(img) {
s_pipe = [
new Sprite(img, 0, 0, 100, 100),
new Sprite(img, 0, 100, 100, 100),
new Sprite(img, 0, 200, 100, 100),
new Sprite(img, 0, 300, 100, 100),
new Sprite(img, 0, 400, 100, 100)
];
s_pipe.color = "#70C5CF";
}