Building a Board Game
Devin Asay
devin_asay at byu.edu
Tue Apr 7 15:48:16 EDT 2020
Roger,
Rather than moving an object, think about using button icons. This is the basic process:
- on mouseDown: check the icon of the target, set the icon of a hidden, moving button to the same icon, set the icon of the target to 0, set a flag—isDragging--to true, show the hidden button
- on mouseMove: if isDragging is true, set the loc of the moving button to the mouseLoc
- on mouseUp: figure out which square you’re over, set the icon of that button to the icon of the moving button, hide moving button, set isDragging to false.
I made a rudimentary chess game that uses this technique, check it out here:
http://dight310.byu.edu/lesson_materials/07-arrays/chessGame-final-key.livecode
Click the Clear Board and Setup Game buttons first to set up the game board array. Game state handlers are in the card script; game piece moving handlers are in the game board group script.
Hope this helps.
Devin
On Apr 7, 2020, at 1:24 PM, Roger Guay via use-livecode <use-livecode at lists.runrev.com<mailto:use-livecode at lists.runrev.com>> wrote:
Hi all,
I know there must be a simple way to do this but it is escaping me at the moment. How can I move an object (grab me on mouseDown) and have it snap to a grid (square on a board game) on mouseUp?
Thanks much,
Roger
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com<mailto:use-livecode at lists.runrev.com>
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Devin Asay
Director
Office of Digital Humanities
Brigham Young University
More information about the use-livecode
mailing list