import { EntityData } from '../model/data/entity'; import { Renderer } from './renderer/renderer'; import { SpriteView, SpriteViewBuilder } from './sprite'; import { loadImage, mkTexture } from './util/image'; export async function loadEntity( r: Renderer, data: EntityData, ): Promise { const tile = await loadImage(`resources/sprite/entity/${data.sprite}.png`); const texture = mkTexture(r.getContext(), tile); const [x, y] = data.anchor; const builder = new SpriteViewBuilder(r, texture); builder.addSprite([-x, -y, -x + 1, -y + 1], [0, 0, 1, 1]); return builder.build(); }