Jump to content

Drag and snap without holding cursor down


mcf
 Share

Recommended Posts

Hi all,

I would like to take advantage of Phaser's nice .enableDrag() and .enableSnap() functions, but without needing to hold down the cursor to trigger the dragging. In other words, I would like a sprite to follow the mouse around while snapping to a grid. An example of what I mean would be having a worker unit build a building in Starcraft -- after selecting the building from the menu, it is attached to the cursor but also snaps to a grid while the cursor is up, and then obviously to place the building you press the cursor down.

I can envision how to write custom code to do this, but was wondering if Phaser has something built-in that I'm missing. Thanks!

Link to comment
Share on other sites

The example you mention is perhaps checking the mouse position over a field and if it passes a certain condition it displays certain visual element in a certain way.

Maybe something like this snap on drag?

My guess is, you press a button with a given asset, the mouse cursor enters a context mode in which you just move it around and the image asset follows it. All other cursor functionality is disabled until you click with the mouse button above the field.

If you click on the menu, the cursor goes back to normal mode.

If you click with the following image asset on the field, it creates brand new building and then reverts the cursor back to normal mode.

Something like this.

P.S. I think in Starcraft there is no snap to grid, it just follows the cursor in context mode and once you press to create building it reverts back to normal mode, for selecting units, etc...

Link to comment
Share on other sites

Yep, I've looked at that "Snap on Grid" example. It's extremely close to what I want. Essentially I want the left Atari (the snapping one) to follow the cursor without needing to hold the cursor down. I thought Phaser.io might have something ready-made for this, but if not I can figure something out no problem.

I had to go watch some gameplay of the original Starcraft. Pretty sure buildings are placed on a grid, but not important either way.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...