/** * Resource handler for the `textureatlas` asset type. Loads a texture and its frame definitions * into a {@link TextureAtlas}. The frames come from the asset data, or from a JSON file. * * The JSON file can be a sprite sheet exported by TexturePacker or Aseprite as JSON, with its * frames as a hash or an array. Each frame is keyed by its name, and the image named by * `meta.image` loads from beside the JSON file. A trimmed frame keeps the position it had in its * untrimmed sprite. Rotated frames are not supported, so export the sheet with rotation disabled. * The JSON file can also hold texture atlas frames, with a PNG image of the same name beside it. * * The image of a JSON file is created with the texture settings in the asset data, such as * `srgb` and `minfilter`, as the image of a texture asset is. * * @example * // a pixel art sprite sheet exported by Aseprite, with frames named "walk 0" to "walk 3" * const asset = new Asset('walk', 'textureatlas', { url: 'sprites/walk.json' }, { * minfilter: 'nearest', * magfilter: 'nearest', * srgb: true * }); * asset.ready(() => { * const sprite = new Sprite(app.graphicsDevice, { * atlas: asset.resource, * frameKeys: ['walk 0', 'walk 1', 'walk 2', 'walk 3'], * pixelsPerUnit: 32 * }); * }); * app.assets.add(asset); * app.assets.load(asset); * * @category Asset */ export class TextureAtlasHandler extends ResourceHandler { /** * Create a new TextureAtlasHandler instance. * * @param {AppBase} app - The running {@link AppBase}. * @ignore */ constructor(app: AppBase); _loader: import("./loader.js").ResourceLoader; load(url: any, callback: any, asset: any): void; /** * Loads the image of a JSON file into a texture of the atlas's own, as the atlas destroys its * texture: the loader's cache could provide a texture another asset owns. A loaded bundle that * holds the image provides it, as it would through the loader. * * @param {string} textureUrl - The url of the image. * @param {Asset} [textureAsset] - The asset whose texture settings create the texture. * @param {function(string|null, Texture=): void} callback - Called with an error or the * texture. * @private */ private _loadImage; open(url: any, data: any, asset: any): TextureAtlas; patch(asset: any, assets: any): void; _onAssetChange(asset: any, attribute: any, value: any): void; } import { ResourceHandler } from './handler.js'; import { TextureAtlas } from '../../scene/texture-atlas.js'; import type { AppBase } from '../app-base.js';