There is a bug in Weltmeister, where sometimes, when adding a new entity by clicking an entity name from the entity spawn menu, it spawns in way off-screen. It's a jarring experience because you have to look at the x/y coordinates in the properties menu, and then hunt around until you find the entity, then bring it back to where you tried to spawn it.
How to reproduce this:
Create an entity with a relatively large width or height (ex. 1000 px).
Click on it to select it (it's properties should appear in the right side menu).
Then click on some empty area to unselect it.
Now try spawning a new, small, regular size entity.
Your new entity just spawned in way over to the left or above.
Why does this happen? Because when selecting an existing entity (via the selectEntityAt function), selector.offset gets set to the difference between where you clicked and the top-left corner of the entity that you clicked.
The problem is however, that this offset gets re-used when spawning a new entity, despite the fact that it corresponds to a different, previous selected entity. We can fix this issue by simply resetting selector.offset to 0 when spawning new entities.
There is a bug in Weltmeister, where sometimes, when adding a new entity by clicking an entity name from the entity spawn menu, it spawns in way off-screen. It's a jarring experience because you have to look at the x/y coordinates in the properties menu, and then hunt around until you find the entity, then bring it back to where you tried to spawn it.
How to reproduce this:
Why does this happen? Because when selecting an existing entity (via the
selectEntityAt
function),selector.offset
gets set to the difference between where you clicked and the top-left corner of the entity that you clicked.https://github.com/phoboslab/Impact/blob/38465b77248696aa7ed173a38e6a00027157eaba/lib/weltmeister/edit-entities.js#L170-L173
This difference gets used to keep the entity under the cursor while dragging it around in the
moveSelectedEntity
function.https://github.com/phoboslab/Impact/blob/38465b77248696aa7ed173a38e6a00027157eaba/lib/weltmeister/edit-entities.js#L268-L274
The problem is however, that this offset gets re-used when spawning a new entity, despite the fact that it corresponds to a different, previous selected entity. We can fix this issue by simply resetting
selector.offset
to0
when spawning new entities.