Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: allow dragging entity by clicking within its bounds in move/scale gizmo

esengine6eb1a29c27fd
diff --git a/editor/src/gizmos/builtinGizmos.ts b/editor/src/gizmos/builtinGizmos.ts
index e5a451c19..387363542 100644
--- a/editor/src/gizmos/builtinGizmos.ts
+++ b/editor/src/gizmos/builtinGizmos.ts
@@ -36,6 +36,22 @@ function getSizeComponentType(entityData: { components: { type: string; data: an
return null;
}
+function hitTestEntityBounds(worldX: number, worldY: number, gctx: GizmoContext): boolean {
+ const entityData = gctx.store.getSelectedEntityData();
+ if (!entityData) return false;
+ const pos = getSelectedEntityPosition(gctx);
+ if (!pos) return false;
+ const worldTransform = gctx.getWorldTransform(entityData.id);
+ const bounds = gctx.getEntityBounds(entityData);
+ const w = bounds.width * Math.abs(worldTransform.scale.x);
+ const h = bounds.height * Math.abs(worldTransform.scale.y);
+ const offsetX = (bounds.offsetX ?? 0) * worldTransform.scale.x;
+ const offsetY = (bounds.offsetY ?? 0) * worldTransform.scale.y;
+ const dx = worldX - pos.x - offsetX;
+ const dy = worldY - pos.y - offsetY;
+ return Math.abs(dx) < w / 2 && Math.abs(dy) < h / 2;
+}
+
// =============================================================================
// Select Gizmo
// =============================================================================
@@ -93,6 +109,9 @@ export function createMoveGizmo(): GizmoDescriptor {
if (dy > 0 && dy < gizmoScale && Math.abs(dx) < handleSize) {
return { hit: true, data: 'y' as DragAxis };
}
+ if (hitTestEntityBounds(worldX, worldY, gctx)) {
+ return { hit: true, data: 'xy' as DragAxis };
+ }
return { hit: false };
},
@@ -397,6 +416,9 @@ export function createScaleGizmo(): GizmoDescriptor {
if (dy > 0 && dy < gizmoScale && Math.abs(dx) < handleSize) {
return { hit: true, data: 'y' as DragAxis };
}
+ if (hitTestEntityBounds(worldX, worldY, gctx)) {
+ return { hit: true, data: 'xy' as DragAxis };
+ }
return { hit: false };
},
diff --git a/editor/src/panels/inspector/EntityInspector.ts b/editor/src/panels/inspector/EntityInspector.ts
index 9887c0028..6cb9761cd 100644
--- a/editor/src/panels/inspector/EntityInspector.ts
+++ b/editor/src/panels/inspector/EntityInspector.ts
@@ -374,7 +374,7 @@ function createSpriteSizeResetButton(
const texture = component.data.texture;
if (!texture) return;
- const relativePath = resolveTexturePath(texture);
+ const relativePath = resolveTexturePath(texture as string);
if (!relativePath) return;
const projectDir = getProjectDir();