@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
94 lines (91 loc) • 3.9 kB
TypeScript
import { SpriteOptions, Sprite, Texture, ContainerEvents, ContainerChild, EventEmitter, TextureSourceLike } from 'pixi.js';
import ICanvasBaseMemory from '../../interface/canvas/ICanvasBaseMemory.js';
import ICanvasSpriteMemory, { ICanvasSpriteBaseMemory } from '../../interface/canvas/ICanvasSpriteMemory.js';
import CanvasEventNamesType from '../../types/CanvasEventNamesType.js';
import CanvasEvent from '../CanvasEvent.js';
import CanvasBase from './CanvasBase.js';
import '../../types/EventIdType.js';
import '../../interface/canvas/ITextureMemory.js';
declare const CANVAS_SPRITE_ID = "CanvasSprite";
/**
* This class is a extension of the [PIXI.Sprite class](https://pixijs.com/8.x/examples/sprite/basic), it has the same properties and methods,
* but it has the ability to be saved and loaded by the Pixi'VN library.
* @example
* ```typescript
* const texture = await Assets.load('https://pixijs.com/assets/bunny.png');
* const sprite = CanvasSprite.from(texture);
*
* sprite.anchor.set(0.5);
* sprite.x = GameWindowManager.screen.width / 2;
* sprite.y = GameWindowManager.screen.height / 2;
*
* sprite.eventMode = 'static';
* sprite.cursor = 'pointer';
* sprite.onEvent('pointerdown', EventTest);
*
* GameWindowManager.addCanvasElement("bunny", sprite);
* ```
*/
declare class CanvasSprite<Memory extends SpriteOptions & ICanvasBaseMemory = ICanvasSpriteMemory> extends Sprite implements CanvasBase<Memory | ICanvasSpriteMemory> {
constructor(options?: SpriteOptions | Texture);
pixivnId: string;
get memory(): Memory | ICanvasSpriteMemory;
set memory(value: ICanvasSpriteMemory);
private _onEvents;
get onEvents(): {
[name: string]: string;
[name: symbol]: string;
};
/**
* is same function as on(), but it keeps in memory the children.
* @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.
* @param eventClass The class that extends CanvasEvent.
* @returns
* @example
* ```typescript
* \@eventDecorator()
* export class EventTest extends CanvasEvent<CanvasSprite> {
* override fn(event: CanvasEventNamesType, sprite: CanvasSprite): void {
* if (event === 'pointerdown') {
* sprite.scale.x *= 1.25;
* sprite.scale.y *= 1.25;
* }
* }
* }
* ```
*
* ```typescript
* let sprite = addImage("alien", 'https://pixijs.com/assets/eggHead.png')
* await sprite.load()
*
* sprite.eventMode = 'static';
* sprite.cursor = 'pointer';
* sprite.onEvent('pointerdown', EventTest);
*
* GameWindowManager.addCanvasElement("bunny", sprite);
* ```
*/
onEvent<T extends CanvasEventNamesType, T2 extends typeof CanvasEvent<typeof this>>(event: T, eventClass: T2): this;
/**
* on() does not keep in memory the event class, use onEvent() instead
* @deprecated
* @private
* @param event
* @param fn
* @param context
*/
on<T extends keyof ContainerEvents<ContainerChild> | keyof {
[K: symbol]: any;
[K: {} & string]: any;
}>(event: T, fn: (...args: EventEmitter.ArgumentMap<ContainerEvents<ContainerChild> & {
[K: symbol]: any;
[K: {} & string]: any;
}>[Extract<T, keyof ContainerEvents<ContainerChild> | keyof {
[K: symbol]: any;
[K: {} & string]: any;
}>]) => void, context?: any): this;
static from(source: Texture | TextureSourceLike, skipCache?: boolean): CanvasSprite<any>;
}
declare function getMemorySprite<T extends CanvasSprite<any>>(element: T | CanvasSprite<any>): ICanvasSpriteMemory;
declare function setMemorySprite<Memory extends ICanvasSpriteBaseMemory>(element: CanvasSprite<any>, memory: Memory): void;
export { CANVAS_SPRITE_ID, CanvasSprite as default, getMemorySprite, setMemorySprite };