Skip to content

Commit

Permalink
Fix drag handling on Safari and Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
chellmuth committed Jan 12, 2014
1 parent a082417 commit 023f0ab
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions web/hive.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,8 +65,16 @@ void start() {


var dragHandler = new DragHandler(canvas); var dragHandler = new DragHandler(canvas);


Point currentPoint, lastPoint;
var adjustCamera = (DragEvent e) { var adjustCamera = (DragEvent e) {
var movement = e.mouseEvent.movement; if (lastPoint == null) {
lastPoint = e.mouseEvent.client;
} else {
lastPoint = currentPoint;
}
currentPoint = e.mouseEvent.client;

var movement = currentPoint - lastPoint;
camera.offsetX += movement.x; camera.offsetX += movement.x;
camera.offsetY += movement.y; camera.offsetY += movement.y;
render(gamestate); render(gamestate);
Expand All @@ -76,8 +84,8 @@ void start() {
isClick = false; isClick = false;
adjustCamera(event); adjustCamera(event);
}); });
dragHandler.onDrag.listen(adjustCamera); dragHandler.onDrag.listen((event) { adjustCamera(event); });
dragHandler.onDragEnd.listen(adjustCamera); dragHandler.onDragEnd.listen((event) { adjustCamera(event); lastPoint = null; });


window.onKeyDown.listen((event) => handleKeyPress(event, gamestate)); window.onKeyDown.listen((event) => handleKeyPress(event, gamestate));
window.onResize.listen((event) { window.onResize.listen((event) {
Expand Down

0 comments on commit 023f0ab

Please sign in to comment.