class BtnGames extends GameObject { buttons = []; buttonPadding = 10; buttonXOffset = -32; state = 0; prevState = 0; menuAnchor = null; static States = { closed: 0, open: 1, moving: 2 }; constructor (x, y, sprite, layer) { super(x, y, sprite, layer); this.menuAnchor = this.transform.position.getCopy(); } addedToScene () { let frogButton = this.scene.addObject(new GameObject(0, 0, this.scene.game.images.btnFrog)); frogButton.onClick = function () { console.log("clicked frog btn"); }; // todo instantiate guy this.buttons = [ this.scene.addObject(frogButton) ]; } onClick (btn) { console.log("clicked games btn"); } onUpdate () { } update (deltaTime) { super.update(deltaTime); for (let i = 0; i < this.buttons.length; i++) { if (i == 0) { this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset; this.buttons[i].transform.position.y = this.menuAnchor.y + this.transform.size.y + this.buttonPadding; } else { this.buttons[i].transform.position.x = this.menuAnchor.x + this.buttonXOffset; this.buttons[i].transform.position.y = this.buttons[i - 1].transform.position.y + this.buttons[i - 1].transform.size.y + this.buttonPadding; } } } }