BlueGit

blue-star speeltuin

fixes on fruitInventory: removal/population sometimes overlapping & prev tween cancelling

timfa wsadhelios · pushed by timfa

Authored 2022-10-23 · 4 years ago

Hash
9733eb94377f557e151ae8effb0a79d029eb4438
Parent
88af4bbe
2 files changed +40 −22
src/minigame/frog/frogScene.js +2 −4
@@ -102,10 +102,8 @@ class FrogScene extends Scene
102 102 }
103 103 if (this.windowDestroyTweens.length > 0)
104 104 {
105 let gameButton = MainMenu.Instance.getChildButton("btnGames").getChildButton("btnFrog");
106 let tween = gameButton.moveToActiveState(800, () => gameButton.moveToInactiveState(800));
107
108 tween.easing(TWEEN.Easing.Back.Out);
105 let frogButton = MainMenu.Instance.getChildButton("btnGames").getChildButton("btnFrog");
106 frogButton.moveToActiveState(800, () => frogButton.moveToInactiveState(800));
109 107
110 108 this.windowDestroyTweens.forEach(t => t.start());
111 109 this.windowDestroyTweens[0].onComplete(() => this.destroy());
@@ -102,10 +102,8 @@ class FrogScene extends Scene
102 }
102 }
103 if (this.windowDestroyTweens.length > 0)
103 if (this.windowDestroyTweens.length > 0)
104 {
104 {
105 let gameButton = MainMenu.Instance.getChildButton("btnGames").getChildButton("btnFrog");
105 let frogButton = MainMenu.Instance.getChildButton("btnGames").getChildButton("btnFrog");
106 let tween = gameButton.moveToActiveState(800, () => gameButton.moveToInactiveState(800));
106 frogButton.moveToActiveState(800, () => frogButton.moveToInactiveState(800));
107
108 tween.easing(TWEEN.Easing.Back.Out);
109
107
110 this.windowDestroyTweens.forEach(t => t.start());
108 this.windowDestroyTweens.forEach(t => t.start());
111 this.windowDestroyTweens[0].onComplete(() => this.destroy());
109 this.windowDestroyTweens[0].onComplete(() => this.destroy());
src/objects/menus/fruitInventory.js +38 −18
@@ -11,6 +11,8 @@ class FruitInventory extends GameObject
11 11
12 12 static Instance = null;
13 13
14 activeTween = null;
15
14 16 fruitInventoryButtons = [];
15 17
16 18 g_inv = null;
@@ -129,44 +131,51 @@ class FruitInventory extends GameObject
129 131 moveToOpen (onDone)
130 132 {
131 133 let context = this;
132 new TWEEN.Tween(this.transform.position)
134 let tween = new TWEEN.Tween(this.transform.position)
133 135 .to({ y: 250 }, 1500)
134 136 .easing(TWEEN.Easing.Elastic.Out)
135 .onComplete(() => { this.state = MenuStates.open; onDone && onDone.call(context); })
136 137 .onUpdate(() => { FruitInventory.Instance.updateFruitsPositions(); })
137 .start();
138 .onComplete(() => { this.state = MenuStates.open; this.activeTween = null; onDone && onDone.call(context); });
138 139
139 this.clearFruitButtons();
140 140
141 let spawnedAndBelowMax = true;
141 tween.onStart(() => { this.clearFruitButtons(); this.stopActiveTween(tween); this.createFruitButtons(); }).start();
142 142
143 for (let t = 0; t < this.scene.game.images.fruit.subImages; t++)
144 {
145 let amount = Math.min(17, this.getFruitAmountOfType(t));
143 let spawnedAndBelowMax = true;
146 144
147 for (let i = 0; i < amount; i++)
148 {
149 this.fruitInventoryButtons.push(this.scene.addObject(new FruitInventoryButton(-50, -50, this.scene.game.images.fruit, 0, t)));
150 }
151 }
152 145 }
153 146
154 147 moveToClose (onDone)
155 148 {
156 149 let context = this;
157 new TWEEN.Tween(this.transform.position)
150 let tween = new TWEEN.Tween(this.transform.position)
158 151 .to({ y: -500 }, 500)
159 152 .easing(TWEEN.Easing.Back.In)
153 .onUpdate(() => { FruitInventory.Instance.updateFruitsPositions(); })
160 154 .onComplete(() =>
161 155 {
162 156 this.state = MenuStates.closed;
163
157 this.activeTween = null;
164 158 this.clearFruitButtons();
165 159
166 160 onDone && onDone.call(context);
167 })
168 .onUpdate(() => { FruitInventory.Instance.updateFruitsPositions(); })
169 .start();
161 });
162
163 tween.onStart(() => this.stopActiveTween(tween)).start();
164 }
165
166 createFruitButtons ()
167 {
168 for (let t = 0; t < this.scene.game.images.fruit.subImages; t++)
169 {
170 let amount = Math.min(17, this.getFruitAmountOfType(t));
171
172 for (let i = 0; i < amount; i++)
173 {
174 this.fruitInventoryButtons.push(this.scene.addObject(new FruitInventoryButton(-50, -50, this.scene.game.images.fruit, 0, t)));
175 }
176 }
177 console.log("creating inv");
178
170 179 }
171 180
172 181 clearFruitButtons ()
@@ -175,5 +184,16 @@ class FruitInventory extends GameObject
175 184 this.fruitInventoryButtons[i].destroy();
176 185
177 186 this.fruitInventoryButtons = [];
187
188 console.log("cleared inv");
189 }
190
191 stopActiveTween (tween)
192 {
193 if (this.activeTween)
194 {
195 this.activeTween.stop();
196 }
197 this.activeTween = tween;
178 198 }
179 199 }
@@ -11,6 +11,8 @@ class FruitInventory extends GameObject
11
11
12 static Instance = null;
12 static Instance = null;
13
13
14 activeTween = null;
15
14 fruitInventoryButtons = [];
16 fruitInventoryButtons = [];
15
17
16 g_inv = null;
18 g_inv = null;
@@ -129,44 +131,51 @@ class FruitInventory extends GameObject
129 moveToOpen (onDone)
131 moveToOpen (onDone)
130 {
132 {
131 let context = this;
133 let context = this;
132 new TWEEN.Tween(this.transform.position)
134 let tween = new TWEEN.Tween(this.transform.position)
133 .to({ y: 250 }, 1500)
135 .to({ y: 250 }, 1500)
134 .easing(TWEEN.Easing.Elastic.Out)
136 .easing(TWEEN.Easing.Elastic.Out)
135 .onComplete(() => { this.state = MenuStates.open; onDone && onDone.call(context); })
136 .onUpdate(() => { FruitInventory.Instance.updateFruitsPositions(); })
137 .onUpdate(() => { FruitInventory.Instance.updateFruitsPositions(); })
137 .start();
138 .onComplete(() => { this.state = MenuStates.open; this.activeTween = null; onDone && onDone.call(context); });
138
139
139 this.clearFruitButtons();
140
140
141 let spawnedAndBelowMax = true;
141 tween.onStart(() => { this.clearFruitButtons(); this.stopActiveTween(tween); this.createFruitButtons(); }).start();
142
142
143 for (let t = 0; t < this.scene.game.images.fruit.subImages; t++)
143 let spawnedAndBelowMax = true;
144 {
145 let amount = Math.min(17, this.getFruitAmountOfType(t));
146
144
147 for (let i = 0; i < amount; i++)
148 {
149 this.fruitInventoryButtons.push(this.scene.addObject(new FruitInventoryButton(-50, -50, this.scene.game.images.fruit, 0, t)));
150 }
151 }
152 }
145 }
153
146
154 moveToClose (onDone)
147 moveToClose (onDone)
155 {
148 {
156 let context = this;
149 let context = this;
157 new TWEEN.Tween(this.transform.position)
150 let tween = new TWEEN.Tween(this.transform.position)
158 .to({ y: -500 }, 500)
151 .to({ y: -500 }, 500)
159 .easing(TWEEN.Easing.Back.In)
152 .easing(TWEEN.Easing.Back.In)
153 .onUpdate(() => { FruitInventory.Instance.updateFruitsPositions(); })
160 .onComplete(() =>
154 .onComplete(() =>
161 {
155 {
162 this.state = MenuStates.closed;
156 this.state = MenuStates.closed;
163
157 this.activeTween = null;
164 this.clearFruitButtons();
158 this.clearFruitButtons();
165
159
166 onDone && onDone.call(context);
160 onDone && onDone.call(context);
167 })
161 });
168 .onUpdate(() => { FruitInventory.Instance.updateFruitsPositions(); })
162
169 .start();
163 tween.onStart(() => this.stopActiveTween(tween)).start();
164 }
165
166 createFruitButtons ()
167 {
168 for (let t = 0; t < this.scene.game.images.fruit.subImages; t++)
169 {
170 let amount = Math.min(17, this.getFruitAmountOfType(t));
171
172 for (let i = 0; i < amount; i++)
173 {
174 this.fruitInventoryButtons.push(this.scene.addObject(new FruitInventoryButton(-50, -50, this.scene.game.images.fruit, 0, t)));
175 }
176 }
177 console.log("creating inv");
178
170 }
179 }
171
180
172 clearFruitButtons ()
181 clearFruitButtons ()
@@ -175,5 +184,16 @@ class FruitInventory extends GameObject
175 this.fruitInventoryButtons[i].destroy();
184 this.fruitInventoryButtons[i].destroy();
176
185
177 this.fruitInventoryButtons = [];
186 this.fruitInventoryButtons = [];
187
188 console.log("cleared inv");
189 }
190
191 stopActiveTween (tween)
192 {
193 if (this.activeTween)
194 {
195 this.activeTween.stop();
196 }
197 this.activeTween = tween;
178 }
198 }
179}
199}