summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-01-08 20:36:58 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-01-08 20:36:58 +0100
commit8acc22138d4fdd0b1ea643e9b7f821fb606c58d1 (patch)
tree2ef141c3c06ca18a1ba9cbdba04ec61e4fe99343
parent8567ed9397b00729c76cc675e9c554133d2612e7 (diff)
downloadrpgedit-8acc22138d4fdd0b1ea643e9b7f821fb606c58d1.tar
rpgedit-8acc22138d4fdd0b1ea643e9b7f821fb606c58d1.zip
MapView: refactor sprite rendering
-rw-r--r--src/view/MapView.ts31
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;
}