diff --git a/README.md b/README.md index 2821c56..419c74b 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ npm install pixijs-actions yarn add pixijs-actions ``` -2. Import `pixijs-actions` somewhere in your application. The global mixins and their types are automatically registered when you import the library. +2. Import `pixijs-actions` somewhere in your application. The DisplayObject mixin and its types are automatically registered when you import the library. 3. Register the global ticker with your PixiJS app (or other render loop): diff --git a/src/Action.ts b/src/Action.ts index 38a4c07..118ea34 100644 --- a/src/Action.ts +++ b/src/Action.ts @@ -97,7 +97,11 @@ export abstract class _ extends Action { * @param categoryMask (Optional) Bitmask to filter which categories of actions to update. * @param onErrorHandler (Optional) Handler errors from each action's tick. */ - public static tick(deltaTimeMs: number, categoryMask: number | undefined = undefined, onErrorHandler?: (error: any) => void): void { + public static tick( + deltaTimeMs: number, + categoryMask: number | undefined = undefined, + onErrorHandler?: (error: any) => void + ): void { ActionTicker.tickAll(deltaTimeMs, categoryMask, onErrorHandler); } diff --git a/src/mixin.ts b/src/DisplayObject.mixin.ts similarity index 91% rename from src/mixin.ts rename to src/DisplayObject.mixin.ts index c1135ac..1146340 100644 --- a/src/mixin.ts +++ b/src/DisplayObject.mixin.ts @@ -3,15 +3,15 @@ import { ActionTicker } from "./lib/ActionTicker"; import { getSpeed } from "./lib/utils/displayobject"; // -// ----- Global Mixin: ----- +// ----- DisplayObject Mixin: ----- // /** - * Register the global mixins for PIXI.DisplayObject. + * Register the mixins for PIXI.DisplayObject. * * @param displayObject A reference to `PIXI.DisplayObject`. */ -export function registerGlobalMixin(displayObject: any): void { +export function registerDisplayObjectMixin(displayObject: any): void { const prototype = displayObject.prototype; // - Properties: diff --git a/src/__tests__/Action.test.ts b/src/__tests__/Action.test.ts index 6df32b0..2b21665 100644 --- a/src/__tests__/Action.test.ts +++ b/src/__tests__/Action.test.ts @@ -1,5 +1,6 @@ import { Container, Sprite } from 'pixi.js'; import { Action, TimingMode } from '../index'; +// import { registerDisplayObjectMixin } from '../DisplayObject.mixin'; function simulateTime(seconds: number, steps: number = 100): void { const tickMs = seconds / steps * 1_000; @@ -10,8 +11,8 @@ function simulateTime(seconds: number, steps: number = 100): void { } } -/** Load the global mixin first. */ -// beforeAll(() => registerGlobalMixin(DisplayObject)); +/** Load the DisplayObject mixin first. */ +// beforeAll(() => registerDisplayObjectMixin(DisplayObject)); describe('DefaultTimingMode static properties', () => { it('should reflect the DefaultTimingModeEaseInOut on the root Action type', () => { diff --git a/src/actions/speed/SpeedToAction.ts b/src/actions/speed/SpeedToAction.ts index 9aba64d..3657db1 100644 --- a/src/actions/speed/SpeedToAction.ts +++ b/src/actions/speed/SpeedToAction.ts @@ -14,7 +14,7 @@ export class SpeedToAction extends Action { return new DelayAction(this.scaledDuration); } - protected onSetupTicker(target: TargetNode, ticker: IActionTicker): any { + protected onSetupTicker(target: TargetNode): any { return { startSpeed: target.speed, }; @@ -24,8 +24,7 @@ export class SpeedToAction extends Action { target: TargetNode, t: number, dt: number, - ticker: IActionTicker, - deltaTime: number, + ticker: IActionTicker ): void { target.speed = ticker.data.startSpeed + (this._speed - ticker.data.startSpeed) * t; } diff --git a/src/index.ts b/src/index.ts index 4aedbb1..d53d201 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,13 +2,13 @@ import * as PIXI from 'pixi.js'; import { _ as Action } from "./Action"; import { TimingMode, TimingModeFn } from "./TimingMode"; -import { registerGlobalMixin } from './mixin'; +import { registerDisplayObjectMixin } from './DisplayObject.mixin'; // -// ----- [Side-effect] Initialize global mixin for DisplayObject: ----- +// ----- [Side-effect] Initialize DisplayObject mixin: ----- // -registerGlobalMixin(PIXI.DisplayObject); +registerDisplayObjectMixin(PIXI.DisplayObject); // // ----- PixiJS Actions library: ----- @@ -16,13 +16,13 @@ registerGlobalMixin(PIXI.DisplayObject); export { Action, - registerGlobalMixin, + registerDisplayObjectMixin, TimingMode, TimingModeFn, }; // -// ----- Types and documentation for the global mixin: ----- +// ----- Types and documentation for the DisplayObject mixin: ----- // declare module 'pixi.js' { diff --git a/src/types.d.ts b/src/types.d.ts index 8367db9..68eade7 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,3 +1,5 @@ +import * as PIXI from 'pixi.js'; + declare global { /** Time measured in seconds. */