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 8addbd30..2ce2ef00 100644 --- a/src/gfx/classes/TexPacker.ts +++ b/src/gfx/classes/TexPacker.ts @@ -34,6 +34,13 @@ 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] { const paddedWidth = img.width + this.padding * 2; const paddedHeight = img.height + this.padding * 2; @@ -41,9 +48,7 @@ export default class TexPacker { if ( paddedWidth > this.canvas.width || paddedHeight > 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