BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / menus / btnGames.js

btnGames.js

a
timfa wsadhelios · pushed by timfa · 4 years ago
622cbaad History
btnGames.js 1.5 KiB Download Raw
1class BtnGames extends GameObject
2{
3 buttons = [];
4 buttonPadding = 10;
5 buttonXOffset = -32;
6 state = 0;
7 prevState = 0;
8
9 menuAnchor = null;
10
11 static States = { closed: 0, open: 1, moving: 2 };
12
13 constructor (x, y, sprite, layer)
14 {
15 super(x, y, sprite, layer);
16
17 this.menuAnchor = this.transform.position.getCopy();
18 }
19
20 addedToScene ()
21 {
22 let frogButton = this.scene.addObject(new GameObject(0, 0, this.scene.game.images.btnFrog));
23 frogButton.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy
24
25 this.buttons =
26 [
27 this.scene.addObject(frogButton)
28 ];
29 }
30
31 onClick (btn)
32 {
33 console.log("clicked games btn");
34 }
35
36 onUpdate ()
37 {
38
39 }
40
41 update (deltaTime)
42 {
43 super.update(deltaTime);
44
45 for (let i = 0; i < this.buttons.length; i++)
46 {
47 if (i == 0)
48 {
49 this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset;
50 this.buttons[i].transform.position.y = this.menuAnchor.y + this.transform.size.y + this.buttonPadding;
51 }
52 else
53 {
54 this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset;
55 this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding;
56 }
57 }
58 }
59}