diff --git a/GameEngine/src/main/java/gameEngine/entites/gameComponents/Draggable.java b/GameEngine/src/main/java/gameEngine/entites/gameComponents/Draggable.java index 367ec19..eec6c1d 100644 --- a/GameEngine/src/main/java/gameEngine/entites/gameComponents/Draggable.java +++ b/GameEngine/src/main/java/gameEngine/entites/gameComponents/Draggable.java @@ -1,5 +1,6 @@ package gameEngine.entites.gameComponents; +import gameEngine.Time; import gameEngine.entites.Entity; import gameEngine.input.Input; import gameEngine.input.MouseInput; @@ -15,28 +16,27 @@ this.isDraggable = draggable; } - protected void handleDragging() { + public void handleDragging() { if (!isDraggable) return; + float mouseX = MouseInput.getX(); float mouseY = MouseInput.getY(); Scene scene = Window.get().getScene(); - if (scene.getSelectedEntity() != null && scene.getSelectedEntity() != parent) { - return; - } - - if (Input.GetMouseButtonDown(0) && isMouseOver(mouseX, mouseY)) { - isDragging = true; - scene.setSelectedEntity(parent); + if (scene.getSelectedEntity() == null) { + if (Input.GetMouseButtonDown(0) && isMouseOver(mouseX, mouseY)) { + isDragging = true; + scene.setSelectedEntity(parent); // エンティティを選択 + } } if (isDragging && Input.GetMouseButton(0)) { - updatePosition(mouseX, mouseY); + updatePosition(mouseX, mouseY); // ドラッグ中は位置を更新 } if (Input.GetMouseButtonUp(0)) { isDragging = false; - scene.clearSelectedEntity(); // ドラッグ解除時に選択をクリア + scene.clearSelectedEntity(); // ドラッグ終了時に選択解除 } }