BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / menus / fruitInventory.js

fruitInventory.js

fruit menu
timfa Tim · pushed by timfa · 4 years ago
8e1c916e History
fruitInventory.js 1.7 KiB Download Raw
1class FruitInventory extends GameObject
2{
3 closeButton = null;
4 closeBtnX = 120;
5 closeBtnY = -140;
6 state = 0;
7
8 constructor (x, y, sprite, layer)
9 {
10 super(x, y, sprite, layer);
11 }
12
13 addedToScene ()
14 {
15 let pos = this.transform.position.add(new vector(this.closeBtnX, this.closeBtnY));
16 this.closeButton = this.scene.addObject(new SubBtn(pos.x, pos.y, this.scene.game.images.closeButton));
17
18 this.moveToClose();
19
20 this.closeButton.isClicked.add(function ()
21 {
22 this.moveToClose();
23 }, this);
24 }
25
26 update (deltaTime)
27 {
28 super.update(deltaTime);
29 let pos = this.transform.position.add(new vector(this.closeBtnX, this.closeBtnY));
30 this.closeButton.transform.position = pos;
31 }
32
33 moveToOpen (onDone)
34 {
35 if (this.state == MenuManager.States.moving)
36 return;
37
38 this.state = MenuManager.States.moving;
39
40 let context = this;
41 new TWEEN.Tween(this.transform.position)
42 .to({ y: 250 }, 1500)
43 .easing(TWEEN.Easing.Elastic.Out)
44 .onComplete(() => { this.state = MenuManager.States.open; onDone && onDone.call(context); })
45 .start();
46 }
47
48 moveToClose (onDone)
49 {
50 if (this.state == MenuManager.States.moving)
51 return;
52
53 this.state = MenuManager.States.moving;
54
55 let context = this;
56 new TWEEN.Tween(this.transform.position)
57 .to({ y: -500 }, 1500)
58 .easing(TWEEN.Easing.Elastic.Out)
59 .onComplete(() => { this.state = MenuManager.States.closed; onDone && onDone.call(context); })
60 .start();
61 }
62}