Hi,
I’m still extremely new to this, so please bear with me if I’m missing something obvious. I decided to try to implement dragging in the PiratePig project, so that the tile you’re attempting to swap tracks mouse movement. I added the following four lines to the TileContainer_onMouseDown
function:
originalTileX = event.target.x; originalTileY = event.target.y; trace("Mouse click at (" + event.stageX + ", " + event.stageY + ")"); trace("Picked up tile at (" + originalTileX + ", " + originalTileY + ")");
as well as the following function:
private function TileContainer_onMouseMove (event:MouseEvent):Void { if (selectedTile != null) { var differenceX = event.stageX - cacheMouse.x; var differenceY = event.stageY - cacheMouse.y; selectedTile.x = originalTileX + differenceX; selectedTile.y = originalTileY + differenceY; trace("Mouse moved to(" + event.stageX + ", " + event.stageY + ")"); trace("Tile moved to (" + selectedTile.x + ", " + selectedTile.y + ")"); } }
(Note that cacheMouse
is just a Point
containing the event.stageX
and event.stageY
properties from the original MOUSE_DOWN
event.)
The strange behavior that I’m seeing is that as I drag the mouse, the tile seems to follow me only about halfway in both the X and Y directions (that is, the farther I move away from the origin, the greater the distance between the tile and the mouse pointer). However, the difference between the X and Y coordinates of the mouse event and those of the tile remains exactly the same.