diff --git a/src/assets/sprite.ts b/src/assets/sprite.ts index ce074b19..c4875c99 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 = { @@ -132,7 +136,9 @@ export class SpriteData { data: ImageSource, opt: LoadSpriteOpt = {}, ): SpriteData { - const [tex, quad] = _k.assets.packer.add(data); + const [tex, quad] = 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/texPacker.ts b/src/gfx/texPacker.ts index 1c94ae94..34f9d8fa 100644 --- a/src/gfx/texPacker.ts +++ b/src/gfx/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