1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import { Renderer } from './renderer/renderer';
import { SpriteView, SpriteViewBuilder } from './sprite';
import { loadImage, mkTexture } from './util/image';
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 [x, y] = anchor;
const builder = new SpriteViewBuilder(r, texture);
builder.addSprite([-x, -y, -x + 1, -y + 1], [0, 0, 1, 1]);
return builder.build();
}
|