From c69138f250535cb0d5787811231efcafb98d7194 Mon Sep 17 00:00:00 2001 From: ArcticFqx Date: Sun, 19 Nov 2023 17:39:52 +0100 Subject: [PATCH] Add items to state --- src/scenes/ShopState.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/scenes/ShopState.ts b/src/scenes/ShopState.ts index b1138d8..7d209df 100644 --- a/src/scenes/ShopState.ts +++ b/src/scenes/ShopState.ts @@ -62,6 +62,8 @@ export class ShopState extends Phaser.GameObjects.Container { private itemsForSale: Item[]; private shopper: Shopper; + private selectedItem: ShopItem | undefined; + constructor(scene: GameScene) { super(scene, 0, 0); this.scene = scene; @@ -109,9 +111,10 @@ export class ShopState extends Phaser.GameObjects.Container { new ShopItem(this.scene, Wstart + itemPositions[i].x * Wdist, Hstart + itemPositions[i].y * Hdist, item.image[0]) ); - items.forEach((elem) => { - elem.on('click', () => { - console.log("click") + items.forEach((item) => { + this.add(item); + item.on('click', () => { + this.selectedItem = item; }); }); }