I'm working on a tile-based game, where objects on the map (characters, items, etc.) are positioned by tile instead of by pixel coordinates. That is, objects would have a tile position variable that controls their real position. I'm wondering how to best implement this, especially for building scenes in the editor.
When working in the editor I assume the most common method is to turn on "Snap to Grid" and set the grid size to my tile size, and for the objects to initialize their tile position variables in their _ready methods. I'd have to make sure that snapping is configured right, while I was hoping to come up with something a bit more automatic.
In Godot 2.1 I discovered an interesting alternative approach using the method
CanvasItem.edit_set_state. It got called when the object is moved in the editor (and the object's script is set to tool mode). I was therefore able to override
edit_set_state to both snap the object to the nearest tile when it was moved in the editor and also update its tile position variable while doing so.
edit_set_state no longer exists in Godot 3.0 though.
How do others handle tile-based placement of objects in tile-based games?