TheRealSlander / Resizable-Selectable-Components

Dynamic components to allow selection, resizing and moving of nodes at runtime in Godot
2 stars 1 forks source link

How to enable grid snapping? #1

Open hermanschaaf opened 3 weeks ago

hermanschaaf commented 3 weeks ago

First, thanks for publishing this library, it's really great!

I've been playing around with it for an hour or two now, but haven't been able to figure out how to enable snapping to a background grid, even though the comments in the code seem to suggest this should be possible. Could you provide some tips or an example for how grid snapping can be achieved?

TheRealSlander commented 3 weeks ago

In this version, I didn't implement the snapping on a grid. Sorry. The snapping I mention in the README is the one between components, which can be enabled/disabled via the padlock button when in edit mode (so a per node activation).

But to answer the question, it should be fairly easy to add snapping against a grid as there is already the mechanic of snapping. Simply add the grid lines coordinates to the comparison in the snapping method and you should be good to go. This would need some modifications as the nodes then need to know about the grid, but it should be quite simple to achieve.

I'll try to implement this feature soon if the time lets me do so '^^