Minor view fixes

This commit is contained in:
Matthias Schiffer 2016-01-05 18:24:27 +01:00
parent 3280ab57bf
commit 7225802966
2 changed files with 9 additions and 10 deletions

View file

@ -1,10 +1,8 @@
html, body { html, body {
width: 100%; width: 100%;
height: 100%; height: 100%;
}
canvas { background: black;
position: absolute;
} }
* { * {

View file

@ -28,11 +28,12 @@ class MapView
@redrawPending = false @redrawPending = false
@canvas = document.createElement 'canvas' @canvas = document.createElement 'canvas'
@ctx = @canvas.getContext '2d' @canvas.style.position = 'absolute'
body.appendChild @canvas body.appendChild @canvas
body.addEventListener 'resize', @setSize @ctx = @canvas.getContext '2d'
window.addEventListener 'resize', @setSize
@setSize() @setSize()
loadTiles(@map.tiles).then (tiles) => loadTiles(@map.tiles).then (tiles) =>
@ -40,12 +41,12 @@ class MapView
@redraw() @redraw()
ready() ready()
drawTile: (x, y, tile) -> drawTile: (x, y, tile) =>
return unless tile return unless tile
@ctx.drawImage(tile, x, y) @ctx.drawImage(tile, x, y)
draw: -> draw: =>
@redrawPending = false @redrawPending = false
@ctx.clearRect 0, 0, @canvas.width, @canvas.height @ctx.clearRect 0, 0, @canvas.width, @canvas.height
@ -64,12 +65,12 @@ class MapView
y += tileSize y += tileSize
redraw: -> redraw: =>
unless @redrawPending unless @redrawPending
@redrawPending = true @redrawPending = true
window.requestAnimationFrame => @draw() window.requestAnimationFrame @draw
setSize: -> setSize: =>
e = document.documentElement e = document.documentElement
@canvas.width = window.innerWidth || e.clientWidth || body.clientWidth @canvas.width = window.innerWidth || e.clientWidth || body.clientWidth
@canvas.height = window.innerHeight || e.clientHeight || body.clientHeight @canvas.height = window.innerHeight || e.clientHeight || body.clientHeight