-
Notifications
You must be signed in to change notification settings - Fork 0
/
TouchColorButtons.js
41 lines (35 loc) · 1015 Bytes
/
TouchColorButtons.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
function ColorButton(color, position) {
this.color = color;
this.position = position;
this.origin = new Vector2(0, 0);
this.scale = 0.6;
this.define();
}
ColorButton.prototype.define = function() {
if (this.color === 'red')
this.sprite = sprites.extras['color_button'].red;
else if (this.color === 'green')
this.sprite = sprites.extras['color_button'].green;
else if (this.color === 'blue')
this.sprite = sprites.extras['color_button'].blue;
this.rect = new Rectangle(
this.position.x ,
this.position.y ,
this.sprite.width,
this.sprite.height
);
}
ColorButton.prototype.draw = function() {
this.rect = new Rectangle(
this.position.x ,
this.position.y ,
this.sprite.width ,
this.sprite.height
);
Canvas.drawImage(this.sprite, this.position, 0, this.origin, this.scale);
}
ColorButton.prototype.update = function() {
if (Touch.containsTouchPress(this.rect)) {
Game.gameWorld.cannon.currentColor = this.color;
}
}