From 77f5684f28f3e30b733f637963c46ed0992157a2 Mon Sep 17 00:00:00 2001 From: chqs-git Date: Thu, 9 Jan 2025 22:14:46 +0000 Subject: [PATCH] Changed to include an option when loading sprites to force the sprite to stay as a single texture and not be placed inside a texture sheet for optimization. --- src/assets/sprite.ts | 6 +++++- src/gfx/classes/TexPacker.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/assets/sprite.ts b/src/assets/sprite.ts index 8410003e..9092adba 100644 --- a/src/assets/sprite.ts +++ b/src/assets/sprite.ts @@ -67,6 +67,10 @@ export interface LoadSpriteOpt { * Animation configuration. */ anims?: SpriteAnims; + /** + * If the sprite is a single image. + */ + singular?: boolean; } export type NineSlice = { @@ -135,7 +139,7 @@ export class SpriteData { data: ImageSource, opt: LoadSpriteOpt = {}, ): SpriteData { - const [tex, quad, packerId] = _k.assets.packer.add(data); + const [tex, quad, packerId] = opt.singular ? _k.assets.packer.add_single(data) : _k.assets.packer.add(data); const frames = opt.frames ? opt.frames.map((f) => new Quad( diff --git a/src/gfx/classes/TexPacker.ts b/src/gfx/classes/TexPacker.ts index 6af9ba49..e1314343 100644 --- a/src/gfx/classes/TexPacker.ts +++ b/src/gfx/classes/TexPacker.ts @@ -32,11 +32,16 @@ export default class TexPacker { this.c2d = context2D; } + // create a image with a single texture + add_single(img: ImageSource): [Texture, Quad, number] { + const tex = Texture.fromImage(this.gfx, img); + this.bigTextures.push(tex); + return [tex, new Quad(0, 0, 1, 1), 0]; + } + add(img: ImageSource): [Texture, Quad, number] { if (img.width > this.canvas.width || img.height > this.canvas.height) { - const tex = Texture.fromImage(this.gfx, img); - this.bigTextures.push(tex); - return [tex, new Quad(0, 0, 1, 1), 0]; + this.add_single(img) } // next row