I've been working on this problem for the last two days and I can't figure it out. Yesterday, I turned to the new Claude 3.7 LLM and it gave me some super helpful pseudocode that does everything perfectly... except my sprites don't align to the 32x32 grid in my level editor. (When I try to drag one sprite under another one, they are not left aligned.) I think this is due to sprite offsets from my pin anchor, but everything I've tried to do to fix this has failed.
What the Code is Supposed to Do:
- Allow me to select sprites using single click, or CTRL click
(I have other events that do multi-select with a rectangle)
- The sprites snap to my 32x32 grid while being dragged
spr_card = my card sprite
fam_cards = family with spr_card as only member (has selected variable, 1 = selected)
spr_anchor = anchor for moving multiple cards
(spr_card and spr_anchor have a center image point)
My Code:
----+ System: Every tick
-----> System: Set snapped_x to snap_enabled ? round(Mouse.X ÷ gridSize) × gridSize : Mouse.X
-----> System: Set snapped_y to snap_enabled ? round(Mouse.Y ÷ gridSize) × gridSize : Mouse.Y
-----> spr_anchor: Set position to (snapped_x, snapped_y)
----+ Mouse: On Left button Clicked on spr_card
----+ spr_card: Pick top instance
--------+ Keyboard: Ctrl is down
---------> spr_card: Set selected to Self.selected = 0
--------+ System: Else
------------+ spr_card: selected = 0
-------------> fam_cards: Set selected to 0
-------------> spr_card: Set selected to 1
------------+ fam_cards: selected = 1
-------------> fam_cards: Pin_Edit Pin to spr_anchor (X: True, Y: True, angle: True, width: No, height: No, Z: False)
----+ Mouse: On Left button released
-----> spr_card: Pin_Edit Unpin