summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-11-11 13:30:15 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-11-11 13:30:15 +0100
commit4eb954e7598983136540b79b46b052a0500f04b3 (patch)
tree15cbce949b482da1eb4ad1350ae5f2c7b900ab4b
parentb83b596b0f79fa1d5b95c462d3fa7171ff221a19 (diff)
downloadrpgedit-4eb954e7598983136540b79b46b052a0500f04b3.tar
rpgedit-4eb954e7598983136540b79b46b052a0500f04b3.zip
view: remove support for non-power-of-2 sprites again
Sprites with unusual dimensions must be padded with transparency. By only supporting power-of-two sprites, the anchor point can always be specified accurately.
-rw-r--r--dist/resources/sprite/entity/red_ellipse.pngbin255 -> 1700 bytes
-rw-r--r--src/view/entity.ts5
-rw-r--r--src/view/util/image.ts14
3 files changed, 8 insertions, 11 deletions
diff --git a/dist/resources/sprite/entity/red_ellipse.png b/dist/resources/sprite/entity/red_ellipse.png
index 48fc2c0..9acf873 100644
--- a/dist/resources/sprite/entity/red_ellipse.png
+++ b/dist/resources/sprite/entity/red_ellipse.png
Binary files differ
diff --git a/src/view/entity.ts b/src/view/entity.ts
index 7600826..83cd955 100644
--- a/src/view/entity.ts
+++ b/src/view/entity.ts
@@ -14,9 +14,10 @@ export async function loadEntity(
const sprites: SpriteView[] = [];
for (let frame = 0; frame < data.frames; frame++) {
- const [texture, size, coords] = mkTexture(r, tile, frame, data.frames);
+ const [texture, coords] = mkTexture(r, tile, frame, data.frames);
- const offset = vec2.mul(vec2.create(), data.anchor, size);
+ const offset = vec2.fromValues(coords[2] - coords[0], coords[3] - coords[1]);
+ vec2.mul(offset, offset, data.anchor);
r.snapToGrid(offset, offset);
const anchorCoords: SpriteCoords = [
diff --git a/src/view/util/image.ts b/src/view/util/image.ts
index 7baeccc..4c5e386 100644
--- a/src/view/util/image.ts
+++ b/src/view/util/image.ts
@@ -16,18 +16,17 @@ export function mkTexture(
src: HTMLCanvasElement|HTMLImageElement,
frame: number = 0,
total: number = 1,
-): [WebGLTexture, [number, number], SpriteCoords] {
+): [WebGLTexture, SpriteCoords] {
const gl = r.getContext();
const texture = gl.createTexture();
if (!texture)
throw new Error('unable to create texture');
const w = src.width, h = src.height / total;
- const w2 = nextPowerOf2(w), h2 = nextPowerOf2(h);
const canvas = document.createElement('canvas');
- canvas.width = w2;
- canvas.height = h2;
+ canvas.width = w;
+ canvas.height = h;
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
ctx.drawImage(src, 0, frame * h, w, h, 0, 0, w, h);
@@ -39,12 +38,9 @@ export function mkTexture(
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
- const size: [number, number] = [
- w / r.coordScale, h / r.coordScale,
- ];
const coords: SpriteCoords = [
- 0, 0, w2 / r.coordScale, h2 / r.coordScale,
+ 0, 0, w / r.coordScale, h / r.coordScale,
];
- return [texture, size, coords];
+ return [texture, coords];
}