| 1 | class 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 | let context = this; |
| 36 | new TWEEN.Tween(this.transform.position) |
| 37 | .to({ y: 250 }, 1500) |
| 38 | .easing(TWEEN.Easing.Elastic.Out) |
| 39 | .onComplete(() => { this.state = MenuManager.States.open; onDone && onDone.call(context); }) |
| 40 | .start(); |
| 41 | } |
| 42 | |
| 43 | moveToClose (onDone) |
| 44 | { |
| 45 | let context = this; |
| 46 | new TWEEN.Tween(this.transform.position) |
| 47 | .to({ y: -500 }, 1500) |
| 48 | .easing(TWEEN.Easing.Elastic.Out) |
| 49 | .onComplete(() => { this.state = MenuManager.States.closed; onDone && onDone.call(context); }) |
| 50 | .start(); |
| 51 | } |
| 52 | } |