diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/view/MapView.ts | 31 |
1 files 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; } |