starling-framework
Version:
A fast, productive library for 2D cross-platform development.
320 lines • 14.4 kB
TypeScript
import TextureOptions from "../textures/TextureOptions";
import TextureAtlas from "../textures/TextureAtlas";
import Texture from "../textures/Texture";
import BitmapFont from "../text/BitmapFont";
import EventDispatcher from "../events/EventDispatcher";
import ByteArray from "openfl/utils/ByteArray";
import SoundTransform from "openfl/media/SoundTransform";
import SoundChannel from "openfl/media/SoundChannel";
import Sound from "openfl/media/Sound";
import Context3DTextureFormat from "openfl/display3D/Context3DTextureFormat";
import Vector from "openfl/Vector";
declare namespace starling.utils {
/**
* Dispatched when all textures have been restored after a context loss.
*/
export class AssetManager extends EventDispatcher {
/**
* Create a new AssetManager. The 'scaleFactor' and 'useMipmaps' parameters define
* * how enqueued bitmaps will be converted to textures.
*/
constructor(scaleFactor?: number, useMipmaps?: boolean);
/**
* Disposes all contained textures, XMLs and ByteArrays.
* *
* * <p>Beware that all references to the assets will remain intact, even though the assets
* * are no longer valid. Call 'purge' if you want to remove all resources and reuse
* * the AssetManager later.</p>
*
*/
dispose(): void;
/**
* Returns a texture with a certain name. The method first looks through the directly
* * added textures; if no texture with that name is found, it scans through all
* * texture atlases.
*/
getTexture(name: string): Texture;
/**
* Returns all textures that start with a certain string, sorted alphabetically
* * (especially useful for "MovieClip").
*/
getTextures(prefix?: string, out?: Vector<Texture>): Vector<Texture>;
/**
* Returns all texture names that start with a certain string, sorted alphabetically.
*/
getTextureNames(prefix?: string, out?: Vector<string>): Vector<string>;
/**
* Returns a texture atlas with a certain name, or null if it's not found.
*/
getTextureAtlas(name: string): TextureAtlas;
/**
* Returns all texture atlas names that start with a certain string, sorted alphabetically.
* * If you pass an <code>out</code>-vector, the names will be added to that vector.
*/
getTextureAtlasNames(prefix?: string, out?: Vector<string>): Vector<string>;
/**
* Returns a sound with a certain name, or null if it's not found.
*/
getSound(name: string): Sound;
/**
* Returns all sound names that start with a certain string, sorted alphabetically.
* * If you pass an <code>out</code>-vector, the names will be added to that vector.
*/
getSoundNames(prefix?: string, out?: Vector<string>): Vector<string>;
/**
* Generates a new SoundChannel object to play back the sound. This method returns a
* * SoundChannel object, which you can access to stop the sound and to control volume.
*/
playSound(name: string, startTime?: number, loops?: number, transform?: SoundTransform): SoundChannel;
/**
* Returns an XML with a certain name, or null if it's not found.
*/
getXml(name: string): any;
/**
* Returns all XML names that start with a certain string, sorted alphabetically.
* * If you pass an <code>out</code>-vector, the names will be added to that vector.
*/
getXmlNames(prefix?: string, out?: Vector<string>): Vector<string>;
/**
* Returns an object with a certain name, or null if it's not found. Enqueued JSON
* * data is parsed and can be accessed with this method.
*/
getObject(name: string): any;
/**
* Returns all object names that start with a certain string, sorted alphabetically.
* * If you pass an <code>out</code>-vector, the names will be added to that vector.
*/
getObjectNames(prefix?: string, out?: Vector<string>): Vector<string>;
/**
* Returns a byte array with a certain name, or null if it's not found.
*/
getByteArray(name: string): ByteArray;
/**
* Returns all byte array names that start with a certain string, sorted alphabetically.
* * If you pass an <code>out</code>-vector, the names will be added to that vector.
*/
getByteArrayNames(prefix?: string, out?: Vector<string>): Vector<string>;
/**
* Returns a bitmaps font with a certain name, or null if it's not found.
*/
getBitmapFont(name: string): BitmapFont;
/**
* Returns all bitmap fonts names that start with a certain string, sorted alphabetically.
* * If you pass an <code>out</code>-vector, the names will be added to that vector.
*/
getBitmapFontNames(prefix?: string, out?: Vector<string>): Vector<string>;
/**
* Register a texture under a certain name. It will be available right away.
* * If the name was already taken, the existing texture will be disposed and replaced
* * by the new one.
*/
addTexture(name: string, texture: Texture): void;
/**
* Register a texture atlas under a certain name. It will be available right away.
* * If the name was already taken, the existing atlas will be disposed and replaced
* * by the new one.
*/
addTextureAtlas(name: string, atlas: TextureAtlas): void;
/**
* Register a sound under a certain name. It will be available right away.
* * If the name was already taken, the existing sound will be replaced by the new one.
*/
addSound(name: string, sound: Sound): void;
/**
* Register an XML object under a certain name. It will be available right away.
* * If the name was already taken, the existing XML will be disposed and replaced
* * by the new one.
*/
addXml(name: string, xml: any): void;
/**
* Register an arbitrary object under a certain name. It will be available right away.
* * If the name was already taken, the existing object will be replaced by the new one.
*/
addObject(name: string, object: any): void;
/**
* Register a byte array under a certain name. It will be available right away.
* * If the name was already taken, the existing byte array will be cleared and replaced
* * by the new one.
*/
addByteArray(name: string, byteArray: ByteArray): void;
/**
* Register a bitmap font under a certain name. It will be available right away.
* * If the name was already taken, the existing font will be disposed and replaced
* * by the new one.
* *
* * <p>Note that the font is <strong>not</strong> registered at the TextField class.
* * This only happens when a bitmap font is loaded via the asset queue.</p>
*
*/
addBitmapFont(name: string, font: BitmapFont): void;
/**
* Removes a certain texture, optionally disposing it.
*/
removeTexture(name: string, dispose?: boolean): void;
/**
* Removes a certain texture atlas, optionally disposing it.
*/
removeTextureAtlas(name: string, dispose?: boolean): void;
/**
* Removes a certain sound.
*/
removeSound(name: string): void;
/**
* Removes a certain Xml object, optionally disposing it.
*/
removeXml(name: string, dispose?: boolean): void;
/**
* Removes a certain object.
*/
removeObject(name: string): void;
/**
* Removes a certain byte array, optionally disposing its memory right away.
*/
removeByteArray(name: string, dispose?: boolean): void;
/**
* Removes a certain bitmap font, optionally disposing it.
*/
removeBitmapFont(name: string, dispose?: boolean): void;
/**
* Empties the queue and aborts any pending load operations.
*/
purgeQueue(): void;
/**
* Removes assets of all types (disposing them along the way), empties the queue and
* * aborts any pending load operations.
*/
purge(): void;
/**
* Enqueues one or more raw assets; they will only be available after successfully
* * executing the "loadQueue" method. This method accepts a variety of different objects:
* *
* * <ul>
* * <li>Strings or URLRequests containing an URL to a local or remote resource. Supported
* * types: <code>png, jpg, gif, atf, mp3, xml, fnt, json, binary</code>.</li>
* * <li>Instances of the File class (AIR only) pointing to a directory or a file.
* * Directories will be scanned recursively for all supported types.</li>
* * <li>Classes that contain <code>static</code> embedded assets.</li>
* * <li>If the file extension is not recognized, the data is analyzed to see if
* * contains XML or JSON data. If it's neither, it is stored as ByteArray.</li>
* * </ul>
* *
* * <p>Suitable object names are extracted automatically: A file named "image.png" will be
* * accessible under the name "image". When enqueuing embedded assets via a class,
* * the variable name of the embedded object will be used as its name. An exception
* * are texture atlases: they will have the same name as the actual texture they are
* * referencing.</p>
* *
* * <p>XMLs that contain texture atlases or bitmap fonts are processed directly: fonts are
* * registered at the TextField class, atlas textures can be acquired with the
* * "getTexture()" method. All other XMLs are available via "getXml()".</p>
* *
* * <p>If you pass in JSON data, it will be parsed into an object and will be available via
* * "getObject()".</p>
*
*/
enqueue(rawAssets: Array<any>): void;
/**
* Enqueues a single asset with a custom name that can be used to access it later.
* * If the asset is a texture, you can also add custom texture options.
* *
* * @param asset The asset that will be enqueued; accepts the same objects as the
* * 'enqueue' method.
* * @param name The name under which the asset will be found later. If you pass null or
* * omit the parameter, it's attempted to generate a name automatically.
* * @param options Custom options that will be used if 'asset' points to texture data.
* * @return the name with which the asset was registered.
*
*/
enqueueWithName(asset: any, name?: string, options?: TextureOptions): string;
/**
* Loads all enqueued assets asynchronously. The 'onProgress' function will be called
* * with a 'ratio' between '0.0' and '1.0', with '1.0' meaning that it's complete.
* *
* * <p>When you call this method, the manager will save a reference to "Starling.current";
* * all textures that are loaded will be accessible only from within this instance. Thus,
* * if you are working with more than one Starling instance, be sure to call
* * "makeCurrent()" on the appropriate instance before processing the queue.</p>
* *
* * @param onProgress <code>function(ratio:Number):void;</code>
*
*/
loadQueue(onProgress: (arg0: number) => void): void;
/**
* Returns the number of raw assets that have been enqueued, but not yet loaded.
*/
get numQueuedAssets(): number;
/**
* When activated, the class will trace information about added/enqueued assets.
* * @default true
*/
get verbose(): boolean;
set verbose(value: boolean)
/**
* Indicates if a queue is currently being loaded.
*/
get isLoading(): boolean;
/**
* For bitmap textures, this flag indicates if mip maps should be generated when they
* * are loaded; for ATF textures, it indicates if mip maps are valid and should be
* * used. @default false
*/
get useMipMaps(): boolean;
set useMipMaps(value: boolean)
/**
* Textures that are created from Bitmaps or ATF files will have the scale factor
* * assigned here. @default 1
*/
get scaleFactor(): number;
set scaleFactor(value: number)
/**
* Textures that are created from Bitmaps will be uploaded to the GPU with the
* * <code>Context3DTextureFormat</code> assigned to this property. @default "bgra"
*/
get textureFormat(): Context3DTextureFormat;
set textureFormat(value: Context3DTextureFormat)
/**
* Indicates if the underlying Stage3D textures should be created as the power-of-two based
* * <code>Texture</code> class instead of the more memory efficient <code>RectangleTexture</code>.
* * @default false
*/
get forcePotTextures(): boolean;
set forcePotTextures(value: boolean)
/**
* Specifies whether a check should be made for the existence of a URL policy file before
* * loading an object from a remote server. More information about this topic can be found
* * in the 'flash.system.LoaderContext' documentation. @default false
*/
get checkPolicyFile(): boolean;
set checkPolicyFile(value: boolean)
/**
* Indicates if atlas XML data should be stored for access via the 'getXml' method.
* * If true, you can access an XML under the same name as the atlas.
* * If false, XMLs will be disposed when the atlas was created. @default false.
*/
get keepAtlasXmls(): boolean;
set keepAtlasXmls(value: boolean)
/**
* Indicates if bitmap font XML data should be stored for access via the 'getXml' method.
* * If true, you can access an XML under the same name as the bitmap font.
* * If false, XMLs will be disposed when the font was created. @default false.
*/
get keepFontXmls(): boolean;
set keepFontXmls(value: boolean)
/**
* The maximum number of parallel connections that are spawned when loading the queue.
* * More connections can reduce loading times, but require more memory. @default 3.
*/
get numConnections(): number;
set numConnections(value: number)
/**
* Indicates if bitmap fonts should be registered with their "face" attribute from the
* * font XML file. Per default, they are registered with the name of the texture file.
* * @default false
*/
get registerBitmapFontsWithFontFace(): boolean;
set registerBitmapFontsWithFontFace(value: boolean)
get_registerBitmapFontsWithFontFace(): boolean;
set_registerBitmapFontsWithFontFace(value: boolean): boolean;
}
}
export default starling.utils.AssetManager;