-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.js
More file actions
32 lines (29 loc) · 996 Bytes
/
Button.js
File metadata and controls
32 lines (29 loc) · 996 Bytes
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
class Button{
constructor(scene, callback, text,config={}){
this.scene = scene; //scene is required
this.text = text;
this.callback = callback;
this.style = config.style;
this.x = config.x ? config.x : width/2;
this.y = config.y ? config.y : height/2 * 0.95;
if(config.autostart){
this.start()
}
}
start(text, callback){
this.text = text ? text:this.text;
this.callback = callback ? callback : this.callback;
let start = this.scene.add.text(this.x, this.y, this.text, this.style);
start.setOrigin(0.5, 0.5);
start.setInteractive();
this.startTween = this.scene.tweens.add({
targets: [start],
duration: 1000,
alpha: 0,
paused: true,
ease: "power0",
onComplete: this.callback
});
start.on('pointerdown', this.startTween.resume, this.startTween);
}
}