BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / menus / 13-subBtn.js

13-subBtn.js

Menu component
timfa Nick Hiert · pushed by timfa · 4 years ago
f555b1c2 History
13-subBtn.js 1.4 KiB Download Raw
1class SubBtn extends GameObject
2{
3 isClicked = null;
4
5 constructor (x, y, sprite, layer)
6 {
7 super(x, y, sprite, layer);
8 this.isClicked = new Signal();
9 }
10
11 onClick (btns)
12 {
13 this.isClicked.dispatch();
14 }
15
16 moveToActiveState (onDone)
17 {
18 this.createOpenTween(onDone);
19 }
20
21 moveToInactiveState (onDone)
22 {
23 this.createCloseTween(onDone);
24 }
25
26 createActiveStateTween (onDone)
27 {
28 let context = this;
29 let tween = new TWEEN.Tween(this.transform.position)
30 .to({ x: this.targetPosition.x, y: this.targetPosition.y }, this.tOpen)
31 .easing(TWEEN.Easing.Bounce.Out)
32 .onComplete(() => { this.activeTween = null; onDone && onDone.call(context); })
33 .start();
34 return tween.onStart(() => this.stopActiveTween(tween));
35 }
36
37 createInactiveStateTween (onDone)
38 {
39 let context = this;
40 let tween = new TWEEN.Tween(this.transform.position)
41 .to({ x: this.originPosition.x, y: this.originPosition.y }, this.tClose)
42 .easing(TWEEN.Easing.Elastic.Out)
43 .onComplete(() => { this.activeTween = null; onDone && onDone.call(context); })
44 .start();
45 return tween.onStart(() => this.stopActiveTween(tween));
46 }
47
48 stopActiveTween (tween)
49 {
50 if (this.activeTween)
51 {
52 this.activeTween.stop();
53 }
54 this.activeTween = tween;
55 }
56}