godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.02k stars 21.17k forks source link

Node2D can only snap on its top-left corner, it should be possible to snap on the node's center #1544

Closed puppetmaster- closed 6 years ago

puppetmaster- commented 9 years ago

image

akien-mga commented 8 years ago

Could you provide an example project? A image is fine, but it's a bit light to really understand an issue...

puppetmaster- commented 8 years ago

the example project http://www.file-upload.net/download-11051501/Issue_1544.zip.html

image

akien-mga commented 8 years ago

Thanks, by checking your example project I was indeed able to reproduce the issue.

The "not_ok" subscene does not snap properly because it's a Node2D with a Polygon2D as a child, contrary to the "ok" subscene which is just a Polygon2D. The Node2D is by default represented by a selectable square of 64x64, so it does not match the 10x10 grid, but it snaps on the top left corner when instanced as a subscene. When Node2D is a main scene, it snaps properly from its center.

akien-mga commented 8 years ago

Actually no, the issue is simpler than that: Node2D simply always snaps at the top-left angle, regardless of whether it's an instanced scene, a root node or a child node. If you move the "issue_1544" node in the above example, the snapping will also be off.

So that's not really a bug per se, but more a consequence of the fixed 64x64 size of the Node2D "select box". To improve this, we'd need either to:

puppetmaster- commented 8 years ago

I can't explain it better :-) I prefer the second one. Node2D should snap on its origin by default.

punto- commented 8 years ago

If it helps, Node2D doesn't have a "size", or an area, like a Control or a Sprite does. It's just a position. So there's no "center".

On 17 November 2015 at 18:23, Rémi Verschelde notifications@github.com wrote:

Actually no, the issue is simpler than that: Node2D simply always snaps at the top-left angle, regardless of whether it's an instanced scene, a root node or a child node. If you move the "issue_1544" node in the above example, the snapping will also be off.

So that's not really a bug per se, but more a consequence of the fixed 64x64 size of the Node2D "select box". To improve this, we'd need either to:

  • Make the size of the select box configurable, so that it can be adapted to the snap grid (e.g. 60x60 would work fine here)
  • Make it possible to configure in a node that it should snap on its origin instead of its top-left corner. That would likely be the best solution, as it can also be desirable in some cases (e.g. have a 20x20 sprite snap properly from its center on a 16x16 tilemap).

— Reply to this email directly or view it on GitHub https://github.com/godotengine/godot/issues/1544#issuecomment-157511446.

akien-mga commented 8 years ago

But when you select it in the editor, it does have a "representation" of some sort, which is a 64x64 square and is affected by snapping. So it should indeed by default snap on its center/position instead of the top-left corner of what is just a visual helper.

puppetmaster- commented 8 years ago

Not only Node2D has this problem also position2d, particles2D, raycast2D and more. Light2D is OK in alpha 2.0

reduz commented 8 years ago

I think the whole snapping should work different, more similar to android studio or modern UI or 2D editors.. with autosnap with aligned elements, guides, etc. Let's do some research together on how to modernize this for 2.1 or later

akien-mga commented 8 years ago

This is related to #4255.

groud commented 7 years ago

If I'm not wrong pivot is now implemented for almost all 2D nodes. We could use this pivot to snap nodes I think.

reduz commented 7 years ago

kicking to 3.1 as not urgent

akien-mga commented 6 years ago

@groud Did your 2D editor changes fix this?

groud commented 6 years ago

Yeah, I think it did.