UNPKG

pencil.js

Version:

Nice modular interactive 2D drawing library.

127 lines (126 loc) 3.47 kB
/** * @module Sprite */ /** * Sprite class * <br><img src="./media/examples/sprite.gif" alt="sprite demo"/> * @class * @extends Image */ export default class Sprite extends Image { /** * * @param {Object} definition - * @return {Sprite} */ static from(definition: any): Sprite; /** * Load and return a spritesheet json file * @param {String} url - Url to the file * @return {Spritesheet} */ static sheet(url: string): Spritesheet; /** * @typedef {Object} Frame * @prop {Number} x - Horizontal position * @prop {Number} y - Vertical position * @prop {Number} w - Width * @prop {Number} h - Height */ /** * @typedef {Object} FrameData * @prop {Frame} frame - Data about this frame in the sprite-sheet * @prop {Frame} spriteSourceSize - Data about the original file */ /** * Sprite constructor * @param {PositionDefinition} positionDefinition - * @param {String} url - * @param {Array<FrameData>} frames - * @param {SpriteOptions} [options] - Drawing options */ constructor(positionDefinition: any, url: string, frames: Array<FrameData>, options?: SpriteOptions); frames: FrameData[]; frame: number; isPaused: boolean; /** * Play the sprite animation * @param {Number} [speed] - Choose a play speed * @return {Sprite} Itself */ play(speed?: number): Sprite; /** * Put the sprite on pause * @return {Sprite} Itself */ pause(): Sprite; /** * * @param {Number} frame - Number of the frame to set * @return {Sprite} Itself */ setFrame(frame: number): Sprite; } export type Frame = { /** * - Horizontal position */ x: number; /** * - Vertical position */ y: number; /** * - Width */ w: number; /** * - Height */ h: number; }; export type FrameData = { /** * - Data about this frame in the sprite-sheet */ frame: Frame; /** * - Data about the original file */ spriteSourceSize: Frame; }; export type SpriteOptions = any; export type SpriteEvents = any; import Image from "@pencil.js/image"; /** * Spritesheet class * @class */ declare class Spritesheet { /** * Spritesheet constructor * @param {Object} json - */ constructor(json: any); json: any; /** * Getter for the image file * @return {Image} */ get file(): Image; /** * Return all the frames corresponding to a selector * @param {String|Function|RegExp} [selector="*"] - Match against the spritesheet images name using a glob pattern, a validation function or a regular expression * @return {Array} */ get(selector?: string | Function | RegExp): any[]; /** * Group images from the spritesheet into a single sprite * @param {PositionDefinition} position - Position of the sprite * @param {String|Function|RegExp} [selector="*"] - Match against the spritesheet images name using a glob pattern, a validation function or a regular expression * @param {ImageOptions} [options] - Options of the sprite * @return {Sprite} */ extract(position: any, selector?: string | Function | RegExp, options?: any): Sprite; } export {};