From bf6d4ee7dc1b2ecabbfef8a90711a12b1e82f82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Sun, 7 Dec 2014 13:19:53 +0100 Subject: [PATCH] Fixed mouseout-error --- src/game.coffee | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/game.coffee b/src/game.coffee index c594ffe..719760a 100644 --- a/src/game.coffee +++ b/src/game.coffee @@ -21,21 +21,32 @@ app.game = @hud.render() mousedown: (event)-> - tile = posToTile(event.x, event.y) - tile.click(event.button) + if @isMouseInView event.x, event.y + tile = posToTile(event.x, event.y) + tile.click(event.button) - @currentSelectedTile.deselect() if @currentSelectedTile - tile.select() - @currentSelectedTile = tile + @currentSelectedTile.deselect() if @currentSelectedTile + tile.select() + @currentSelectedTile = tile mousemove: (event)-> - tile = posToTile(event.x, event.y) + if @isMouseInView event.x, event.y + tile = posToTile(event.x, event.y) - if tile - if tile != @currentHoveredTile - tile.moveIn() - @currentHoveredTile.moveOut() - @currentHoveredTile = tile + if tile + if tile != @currentHoveredTile + tile.moveIn() + @currentHoveredTile.moveOut() if @currentHoveredTile + @currentHoveredTile = tile + else + @currentHoveredTile.moveOut() if @currentHoveredTile + @currentHoveredTile = null + + isMouseInView: (mouseX, mouseY) -> + if mouseX < app.width and mouseX >= 0 and mouseY < app.height and mouseY >= 0 + return true + + false keyup: (event) -> switch event.key