From c0017d66d8463f16ef2565bc38fc853d6f8101cc Mon Sep 17 00:00:00 2001 From: OfficialCHenry Date: Wed, 13 Apr 2022 16:28:09 -0400 Subject: [PATCH] fixed button bug wolfie2d wasnt scaling mouseclick position according to zoom --- src/Wolfie2D/Input/Input.ts | 4 +++- src/Wolfie2D/Nodes/UIElement.ts | 1 - src/shattered_sword/Scenes/GameLevel.ts | 22 ++++++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Wolfie2D/Input/Input.ts b/src/Wolfie2D/Input/Input.ts index cbcf756..75d501c 100644 --- a/src/Wolfie2D/Input/Input.ts +++ b/src/Wolfie2D/Input/Input.ts @@ -299,12 +299,14 @@ export default class Input { return Input.mousePosition.clone().scale(1 / this.viewport.getZoomLevel()).add(Input.viewport.getOrigin()); } + + // -- MODIFIED BY HENRY -> added a scaling /** * Gets the position of the last mouse press * @returns The mouse position stored as a Vec2 */ static getMousePressPosition(): Vec2 { - return Input.mousePressPosition; + return Input.mousePressPosition.scaled(1 / this.viewport.getZoomLevel()); } /** diff --git a/src/Wolfie2D/Nodes/UIElement.ts b/src/Wolfie2D/Nodes/UIElement.ts index f6cb36b..3d8915a 100644 --- a/src/Wolfie2D/Nodes/UIElement.ts +++ b/src/Wolfie2D/Nodes/UIElement.ts @@ -84,7 +84,6 @@ export default abstract class UIElement extends CanvasNode { let clickPos = Input.getMousePressPosition(); if(this.contains(clickPos.x, clickPos.y) && this.visible && !this.layer.isHidden()){ this.isClicked = true; - if(this.onClick !== null){ this.onClick(); } diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index ef8761b..7aa06f8 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -28,6 +28,7 @@ import Item from "../GameSystems/items/Item"; import Layer from "../../Wolfie2D/Scene/Layer"; import Button from "../../Wolfie2D/Nodes/UIElements/Button"; import { Buff } from "../Player/PlayerController"; +import CanvasNode from "../../Wolfie2D/Nodes/CanvasNode"; @@ -102,9 +103,12 @@ export default class GameLevel extends Scene { this.load.image("inventorySlot", "shattered_sword_assets/sprites/inventory.png"); this.load.spritesheet("test_dummy","shattered_sword_assets/spritesheets/test_dummy.json") + + } startScene(): void { + //call super after extending story with scene @@ -166,6 +170,9 @@ export default class GameLevel extends Scene { updateScene(deltaT: number){ + let clickpos = Input.getMousePosition(); + if(Input.isMouseJustPressed()) + console.log("mouse pos: " +clickpos); // Handle events and update the UI if needed while(this.receiver.hasNextEvent()){ let event = this.receiver.getNextEvent(); @@ -193,17 +200,14 @@ export default class GameLevel extends Scene { break; case "buff1": - console.log("button 1 pressed"); (this.player._ai).addBuff(this.buffs[0]); this.buffLayer.disable(); break; case "buff2": - console.log("button 2 pressed"); (this.player._ai).addBuff(this.buffs[1]); this.buffLayer.disable(); break; case "buff3": - console.log("button 3 pressed"); (this.player._ai).addBuff(this.buffs[2]); this.buffLayer.disable(); break; @@ -356,15 +360,23 @@ export default class GameLevel extends Scene { //TODO - //determine button location this.buffButton1 =