How do I use pin (with multi-select and drag) on a grid?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • 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

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Are all sprites the same size, and have the origin point position in the same spot?

    Check out this demo:

    howtoconstructdemos.com/select-and-drag-multiple-images

  • Thanks, dop2000! I hadn't seen this tutorial!

  • I finally decided to snap single selected sprites directly to my grid. For multiple selected sprites, I now set an anchor pin on the lowest selected sprite, pin all selected cards to it, snap the anchor to the grid, and then unpin everything.

    At first, I was trying to do all of this in a single action, which wasn’t working. Adding small (0) waits seems to have fixed it, but it feels messy.

    Is there a better way to handle this in Construct 3, or is this standard practice?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)