summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 22:10:54 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 22:10:54 +0100
commitb08479af405ba3f1b8448f8e2acd23ff9b533087 (patch)
tree784684200101d83f0fdd9e1f59358fd4e236c8a8 /src/view
parent1f9cd7a110e4fe1cf3b4eb220a083fa0f9b0cf98 (diff)
downloadrpgedit-b08479af405ba3f1b8448f8e2acd23ff9b533087.tar
rpgedit-b08479af405ba3f1b8448f8e2acd23ff9b533087.zip
view: make entity anchor point configurable, default to center
Diffstat (limited to 'src/view')
-rw-r--r--src/view/entity.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/view/entity.ts b/src/view/entity.ts
index d95d924..57969a2 100644
--- a/src/view/entity.ts
+++ b/src/view/entity.ts
@@ -2,14 +2,17 @@ import Renderer from './renderer/Renderer';
import { SpriteCoords, SpriteView, SpriteViewBuilder } from './sprite';
import { loadImage, mkTexture } from './util/image';
-export async function loadSimpleEntity(r: Renderer, sprite: string): Promise<SpriteView> {
+export async function loadSimpleEntity(
+ r: Renderer,
+ sprite: string,
+ anchor: [number, number] = [0.5, 0.5],
+): Promise<SpriteView> {
const tile = await loadImage(`resources/sprite/entity/${sprite}.png`);
const texture = mkTexture(r.getContext(), tile);
- const builder = new SpriteViewBuilder(r, texture);
-
- const coords: SpriteCoords = [0, 0, 1, 1];
- builder.addSprite(coords, coords);
+ const [x, y] = anchor;
+ const builder = new SpriteViewBuilder(r, texture);
+ builder.addSprite([-x, -y, 1 - x, 1 - y], [0, 0, 1, 1]);
return builder.build();
}