mcf Posted April 3, 2017 Share Posted April 3, 2017 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 More sharing options...
spinnerbox Posted April 3, 2017 Share Posted April 3, 2017 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 More sharing options...
mcf Posted April 3, 2017 Author Share Posted April 3, 2017 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 More sharing options...
spinnerbox Posted April 3, 2017 Share Posted April 3, 2017 Maybe add button which enables the drag instead of clicking the image with cursor. I don't think the snap/drag is the problem, I think you just need to add different way when to enable or disable it. Link to comment Share on other sites More sharing options...
spinnerbox Posted April 3, 2017 Share Posted April 3, 2017 Follow mouse? Maybe you can add snap as well Link to comment Share on other sites More sharing options...
Recommended Posts