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