From 8acc22138d4fdd0b1ea643e9b7f821fb606c58d1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 8 Jan 2016 20:36:58 +0100 Subject: MapView: refactor sprite rendering --- src/view/MapView.ts | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/view/MapView.ts b/src/view/MapView.ts index 282b819..0c7b8a3 100644 --- a/src/view/MapView.ts +++ b/src/view/MapView.ts @@ -121,6 +121,18 @@ export default class MapView { this.redraw() } + private drawSprite(img: HTMLImageElement, srcX: number, srcY: number, destX: number, destY: number): void { + this.ctx.drawImage( + img, + tiles(srcX), tiles(srcY), + tileSize, tileSize, + tiles(destX)*this.scale, + tiles(destY)*this.scale, + tileSize*this.scale, + tileSize*this.scale + ); + } + private drawTile(x: number, y: number, tile: TileData): void { if (!tile) return; @@ -129,15 +141,7 @@ export default class MapView { if (!img) return; - this.ctx.drawImage( - img, - tiles(tile.subtile || 0), 0, - tileSize, tileSize, - tiles(x)*this.scale, - tiles(y)*this.scale, - tileSize*this.scale, - tileSize*this.scale - ); + this.drawSprite(img, tile.subtile || 0, 0, x, y); } private drawEntity(e: EntityPosition, time: number): boolean { @@ -146,14 +150,7 @@ export default class MapView { return false; var p = entityPosition(e, time); - - this.ctx.drawImage( - sprite, - tiles(e.direction), 0, - tileSize, tileSize, - tiles(p.x)*this.scale, tiles(p.y)*this.scale, - tileSize*this.scale, tileSize*this.scale - ); + this.drawSprite(sprite, e.direction, 0, p.x, p.y); return !!e.transition; } -- cgit v1.2.3