pixi-solid 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { onResize } from "./on-resize.js";
2
- import { PixiApplication, TickerProvider, delay, getPixiApp, getTicker, onTick } from "./pixi-application.js";
2
+ import { PixiApplication, TickerProvider, createAsyncDelay, delay, getPixiApp, getTicker, onTick } from "./pixi-application.js";
3
3
  import { PixiCanvas } from "./pixi-canvas.js";
4
4
  import { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite } from "./pixi-components.js";
5
5
  import { PIXI_EVENT_NAMES, PIXI_SOLID_EVENT_HANDLER_NAMES } from "./pixi-events.js";
@@ -26,6 +26,7 @@ export {
26
26
  Text,
27
27
  TickerProvider,
28
28
  TilingSprite,
29
+ createAsyncDelay,
29
30
  delay,
30
31
  getPixiApp,
31
32
  getTicker,
@@ -1,8 +1,8 @@
1
1
  import { createComponent } from "solid-js/web";
2
- import { Ticker, Application } from "pixi.js";
2
+ import { Application } from "pixi.js";
3
3
  import { createContext, useContext, splitProps, createResource, createEffect, onCleanup, Show } from "solid-js";
4
4
  const PixiAppContext = createContext();
5
- const TickerContext = createContext(Ticker.shared);
5
+ const TickerContext = createContext();
6
6
  const getPixiApp = () => {
7
7
  const app = useContext(PixiAppContext);
8
8
  if (!app) {
@@ -85,11 +85,7 @@ const onTick = (tickerCallback) => {
85
85
  ticker.remove(tickerCallback);
86
86
  });
87
87
  };
88
- const delay = async (delayMs, callback) => {
89
- const ticker = useContext(TickerContext);
90
- if (!ticker) {
91
- throw new Error("delay must be used within a PixiApplication or a TickerProvider");
92
- }
88
+ const asyncDelay = async (ticker, delayMs) => {
93
89
  let timeDelayed = 0;
94
90
  let resolvePromise;
95
91
  const promise = new Promise((resolve) => {
@@ -98,16 +94,38 @@ const delay = async (delayMs, callback) => {
98
94
  const internalCallback = () => {
99
95
  timeDelayed += ticker.deltaMS;
100
96
  if (timeDelayed < delayMs) return;
101
- callback?.();
102
97
  resolvePromise();
103
98
  };
104
99
  ticker.add(internalCallback);
105
100
  await promise;
106
101
  ticker.remove(internalCallback);
107
102
  };
103
+ const createAsyncDelay = () => {
104
+ const ticker = useContext(TickerContext);
105
+ if (!ticker) {
106
+ throw new Error("`createDelay` must be used within a PixiApplication or a TickerProvider. The returned `delay` function can be called in an async context but `createDelay` must be called in a synchronous scope within a PixiApplication or a TickerProvider");
107
+ }
108
+ const delayWithTicker = (delayMs) => asyncDelay(ticker, delayMs);
109
+ return delayWithTicker;
110
+ };
111
+ const delay = (delayMs, callback) => {
112
+ const ticker = useContext(TickerContext);
113
+ if (!ticker) {
114
+ throw new Error("`createDelay` must be used within a PixiApplication or a TickerProvider. The returned `delay` function can be called in an async context but `createDelay` must be called in a synchronous scope within a PixiApplication or a TickerProvider");
115
+ }
116
+ let timeDelayed = 0;
117
+ const internalCallback = () => {
118
+ timeDelayed += ticker.deltaMS;
119
+ if (timeDelayed < delayMs) return;
120
+ callback?.();
121
+ ticker.remove(internalCallback);
122
+ };
123
+ ticker.add(internalCallback);
124
+ };
108
125
  export {
109
126
  PixiApplication,
110
127
  TickerProvider,
128
+ createAsyncDelay,
111
129
  delay,
112
130
  getPixiApp,
113
131
  getTicker,
@@ -1 +1 @@
1
- {"version":3,"file":"pixi-application.js","sources":["../src/pixi-application.tsx"],"sourcesContent":["import type { ApplicationOptions, TickerCallback } from \"pixi.js\";\nimport { Application, Ticker } from \"pixi.js\";\nimport type { JSX, ParentProps, Ref } from \"solid-js\";\nimport { createContext, createEffect, createResource, onCleanup, Show, splitProps, useContext } from \"solid-js\";\n\nconst PixiAppContext = createContext<Application>();\nconst TickerContext = createContext<Ticker>(Ticker.shared);\n\n/**\n * A custom SolidJS hook to access the root PIXI.Application instance.\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n *\n * @returns The PIXI.Application instance provided by the `PixiApplication` component.\n * @throws Will throw an error if used outside of a `PixiApplication` context provider.\n */\nexport const getPixiApp = () => {\n const app = useContext(PixiAppContext);\n if (!app) {\n throw new Error(\"getPixiApp must be used within a PixiApplication\");\n }\n return app;\n};\n\n/**\n * Props for the `PixiApplication` component. It extends the PIXI.ApplicationOptions\n * to allow passing configuration directly to the Pixi.js Application constructor,\n * but omits properties that are handled by the component itself.\n */\nexport type PixiApplicationProps = Partial<Omit<ApplicationOptions, \"children\" | \"resizeTo\">> & {\n ref?: Ref<Application>;\n children?: JSX.Element;\n};\n\n/**\n * A SolidJS component that creates and manages a PIXI.Application instance.\n * It provides the application instance through context to be used by child components\n * and custom hooks like `getPixiApp`, `onTick`, and `getTicker`.\n *\n * This component should only be used once in your application.\n *\n * @param props The properties to configure the Pixi.js Application.\n *\n */\nexport const PixiApplication = (props: PixiApplicationProps) => {\n const [, initialisationProps] = splitProps(props, [\"ref\", \"children\"]);\n\n // TODO: Split props into initialisation props and runtime props\n\n const [appResource] = createResource(async () => {\n const app = new Application();\n await app.init({\n autoDensity: true,\n resolution: Math.min(window.devicePixelRatio, 2),\n sharedTicker: true,\n ...initialisationProps,\n });\n\n return app;\n });\n\n createEffect(() => {\n const app = appResource();\n if (app) {\n if (props.ref) {\n // Solid converts the ref prop to a callback function\n (props.ref as unknown as (arg: any) => void)(app);\n }\n\n // TODO: Go through the other props that can be set at runtime and apply them here\n // e.g. backgroundColor => app.renderer.backgroundColor, etc.\n\n app.ticker.autoStart = false;\n app.ticker.start();\n\n onCleanup(() => {\n app.destroy(true, { children: true });\n });\n }\n });\n\n return (\n <Show when={appResource()}>\n {(app) => (\n <PixiAppContext.Provider value={app()}>\n <TickerContext.Provider value={app().ticker}>{props.children}</TickerContext.Provider>\n </PixiAppContext.Provider>\n )}\n </Show>\n );\n};\n\nexport type TickerProviderProps = ParentProps<{ ticker: Ticker }>;\n\n/**\n * This is only required if you want a ticker without the Application.\n * It provides context for the `onTick` and `getTicker` hooks so we can run tests that use them without having to instantate a Pixi Application.\n *\n * You need to pass in the ticker instance you want to use so it can be manually controled form the outside for testing.\n */\nexport const TickerProvider = (props: TickerProviderProps) => {\n return <TickerContext.Provider value={props.ticker}>{props.children}</TickerContext.Provider>;\n};\n\n/**\n * getTicker\n *\n * A custom SolidJS hook that provides access to the PIXI.Application's shared Ticker instance.\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n * Or a descendant of `TickerProvider` if being used for testing without an application.\n *\n * @returns The PIXI.Ticker instance from the application context.\n * @throws Will throw an error if used outside of a `PixiApplication` or `TickerProvider` context.\n */\nexport const getTicker = (): Ticker => {\n const ticker = useContext(TickerContext);\n if (!ticker) {\n throw new Error(\"getTicker must be used within a PixiApplication or a TickerProvider\");\n }\n return ticker;\n};\n\n/**\n * onTick\n *\n * A custom SolidJS hook that registers a callback function to be executed on every frame\n * of the PIXI.Application's ticker. The callback is automatically removed when the\n * component or hook's owning computation is cleaned up.\n *\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n * Or a descendant of `TickerProvider` if being used for testing without an application.\n *\n * @param tickerCallback - The function to call on each ticker update. It receives\n * the `PIXI.Ticker` instance as its argument.\n *\n */\nexport const onTick = (tickerCallback: TickerCallback<Ticker>): void => {\n const ticker = useContext(TickerContext);\n\n if (!ticker) {\n throw new Error(\"onTick must be used within a PixiApplication or a TickerProvider\");\n }\n\n ticker.add(tickerCallback);\n onCleanup(() => {\n ticker.remove(tickerCallback);\n });\n};\n\n/**\n * Delay until a given number of milliseconds has passed on the shared ticker.\n *\n * It is guaranteed to be in sync with the shared ticker and uses accumulated deltaMs not an external time measurement.\n *\n * Simply await for it to resolve if in an async context or pass in a callback function.\n * It's not recommended to use both techniques at once.\n *\n * @param delayMs - Number of milliseconds to wait (measured in the ticker's time units).\n *\n * @param callback - Optional callback function that will fire when the delayMs time has passed.\n *\n * @returns A Promise that resolves once the ticker's time has advanced by `delayMs`.\n *\n * @throws {Error} If called outside of a `PixiApplication` or `TickerProvider` context.\n *\n * @note It will not resolve or fire the callback if the ticker is paused or stopped.\n *\n */\nexport const delay = async (delayMs: number, callback?: () => void): Promise<void> => {\n const ticker = useContext(TickerContext);\n\n if (!ticker) {\n throw new Error(\"delay must be used within a PixiApplication or a TickerProvider\");\n }\n\n let timeDelayed = 0;\n\n let resolvePromise: (value: void | PromiseLike<void>) => void;\n\n const promise = new Promise<void>((resolve) => {\n resolvePromise = resolve;\n });\n\n const internalCallback = () => {\n timeDelayed += ticker.deltaMS;\n if (timeDelayed < delayMs) return;\n callback?.();\n resolvePromise();\n };\n\n ticker.add(internalCallback);\n\n await promise;\n\n ticker.remove(internalCallback);\n};\n"],"names":["PixiAppContext","createContext","TickerContext","Ticker","shared","getPixiApp","app","useContext","Error","PixiApplication","props","initialisationProps","splitProps","appResource","createResource","Application","init","autoDensity","resolution","Math","min","window","devicePixelRatio","sharedTicker","createEffect","ref","ticker","autoStart","start","onCleanup","destroy","children","_$createComponent","Show","when","Provider","value","TickerProvider","getTicker","onTick","tickerCallback","add","remove","delay","delayMs","callback","timeDelayed","resolvePromise","promise","Promise","resolve","internalCallback","deltaMS"],"mappings":";;;AAKA,MAAMA,iBAAiBC,cAAAA;AACvB,MAAMC,gBAAgBD,cAAsBE,OAAOC,MAAM;AASlD,MAAMC,aAAaA,MAAM;AAC9B,QAAMC,MAAMC,WAAWP,cAAc;AACrC,MAAI,CAACM,KAAK;AACR,UAAM,IAAIE,MAAM,kDAAkD;AAAA,EACpE;AACA,SAAOF;AACT;AAsBO,MAAMG,kBAAkBA,CAACC,UAAgC;AAC9D,QAAM,CAAA,EAAGC,mBAAmB,IAAIC,WAAWF,OAAO,CAAC,OAAO,UAAU,CAAC;AAIrE,QAAM,CAACG,WAAW,IAAIC,eAAe,YAAY;AAC/C,UAAMR,MAAM,IAAIS,YAAAA;AAChB,UAAMT,IAAIU,KAAK;AAAA,MACbC,aAAa;AAAA,MACbC,YAAYC,KAAKC,IAAIC,OAAOC,k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AM,qEAAqE;AAAA,EACvF;AACA,SAAOkB;AACT;AAgBO,MAAMa,SAASA,CAACC,mBAAiD;AACtE,QAAMd,SAASnB,WAAWL,aAAa;AAEvC,MAAI,CAACwB,QAAQ;AACX,UAAM,IAAIlB,MAAM,kEAAkE;AAAA,EACpF;AAEAkB,SAAOe,IAAID,cAAc;AACzBX,YAAU,MAAM;AACdH,WAAOgB,OAAOF,cAAc;AAAA,EAC9B,CAAC;AACH;AAqBO,MAAMG,QAAQ,OAAOC,SAAiBC,aAAyC;AACpF,QAAMnB,SAASnB,WAAWL,aAAa;AAEvC,MAAI,CAACwB,QAAQ;AACX,UAAM,IAAIlB,MAAM,iEAAiE;AAAA,EACnF;AAEA,MAAIsC,cAAc;AAElB,MAAIC;AAEJ,QAAMC,UAAU,IAAIC,QAAeC,CAAAA,YAAY;AAC7CH,qBAAiBG;AAAAA,EACnB,CAAC;AAED,QAAMC,mBAAmBA,MAAM;AAC7BL,mBAAepB,OAAO0B;AACtB,QAAIN,cAAcF,QAAS;AAC3BC,eAAAA;AACAE,mBAAAA;AAAAA,EACF;AAEArB,SAAOe,IAAIU,gBAAgB;AAE3B,QAAMH;AAENtB,SAAOgB,OAAOS,gBAAgB;AAChC;"}
1
+ {"version":3,"file":"pixi-application.js","sources":["../src/pixi-application.tsx"],"sourcesContent":["import type { ApplicationOptions, Ticker, TickerCallback } from \"pixi.js\";\nimport { Application } from \"pixi.js\";\nimport type { JSX, ParentProps, Ref } from \"solid-js\";\nimport { createContext, createEffect, createResource, onCleanup, Show, splitProps, useContext } from \"solid-js\";\n\nconst PixiAppContext = createContext<Application>();\nconst TickerContext = createContext<Ticker>();\n\n/**\n * A custom SolidJS hook to access the root PIXI.Application instance.\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n *\n * @returns The PIXI.Application instance provided by the `PixiApplication` component.\n * @throws Will throw an error if used outside of a `PixiApplication` context provider.\n */\nexport const getPixiApp = () => {\n const app = useContext(PixiAppContext);\n if (!app) {\n throw new Error(\"getPixiApp must be used within a PixiApplication\");\n }\n return app;\n};\n\n/**\n * Props for the `PixiApplication` component. It extends the PIXI.ApplicationOptions\n * to allow passing configuration directly to the Pixi.js Application constructor,\n * but omits properties that are handled by the component itself.\n */\nexport type PixiApplicationProps = Partial<Omit<ApplicationOptions, \"children\" | \"resizeTo\">> & {\n ref?: Ref<Application>;\n children?: JSX.Element;\n};\n\n/**\n * A SolidJS component that creates and manages a PIXI.Application instance.\n * It provides the application instance through context to be used by child components\n * and custom hooks like `getPixiApp`, `onTick`, and `getTicker`.\n *\n * This component should only be used once in your application.\n *\n * @param props The properties to configure the Pixi.js Application.\n *\n */\nexport const PixiApplication = (props: PixiApplicationProps) => {\n const [, initialisationProps] = splitProps(props, [\"ref\", \"children\"]);\n\n // TODO: Split props into initialisation props and runtime props\n\n const [appResource] = createResource(async () => {\n const app = new Application();\n await app.init({\n autoDensity: true,\n resolution: Math.min(window.devicePixelRatio, 2),\n sharedTicker: true,\n ...initialisationProps,\n });\n\n return app;\n });\n\n createEffect(() => {\n const app = appResource();\n if (app) {\n if (props.ref) {\n // Solid converts the ref prop to a callback function\n (props.ref as unknown as (arg: any) => void)(app);\n }\n\n // TODO: Go through the other props that can be set at runtime and apply them here\n // e.g. backgroundColor => app.renderer.backgroundColor, etc.\n\n app.ticker.autoStart = false;\n app.ticker.start();\n\n onCleanup(() => {\n app.destroy(true, { children: true });\n });\n }\n });\n\n return (\n <Show when={appResource()}>\n {(app) => (\n <PixiAppContext.Provider value={app()}>\n <TickerContext.Provider value={app().ticker}>{props.children}</TickerContext.Provider>\n </PixiAppContext.Provider>\n )}\n </Show>\n );\n};\n\nexport type TickerProviderProps = ParentProps<{ ticker: Ticker }>;\n\n/**\n * This is only required if you want a ticker without the Application.\n * It provides context for the `onTick` and `getTicker` hooks so we can run tests that use them without having to instantate a Pixi Application.\n *\n * You need to pass in the ticker instance you want to use so it can be manually controled form the outside for testing.\n */\nexport const TickerProvider = (props: TickerProviderProps) => {\n return <TickerContext.Provider value={props.ticker}>{props.children}</TickerContext.Provider>;\n};\n\n/**\n * getTicker\n *\n * A custom SolidJS hook that provides access to the PIXI.Application's shared Ticker instance.\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n * Or a descendant of `TickerProvider` if being used for testing without an application.\n *\n * @returns The PIXI.Ticker instance from the application context.\n * @throws Will throw an error if used outside of a `PixiApplication` or `TickerProvider` context.\n */\nexport const getTicker = (): Ticker => {\n const ticker = useContext(TickerContext);\n if (!ticker) {\n throw new Error(\"getTicker must be used within a PixiApplication or a TickerProvider\");\n }\n return ticker;\n};\n\n/**\n * onTick\n *\n * A custom SolidJS hook that registers a callback function to be executed on every frame\n * of the PIXI.Application's ticker. The callback is automatically removed when the\n * component or hook's owning computation is cleaned up.\n *\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n * Or a descendant of `TickerProvider` if being used for testing without an application.\n *\n * @param tickerCallback - The function to call on each ticker update. It receives\n * the `PIXI.Ticker` instance as its argument.\n *\n */\nexport const onTick = (tickerCallback: TickerCallback<Ticker>): void => {\n const ticker = useContext(TickerContext);\n\n if (!ticker) {\n throw new Error(\"onTick must be used within a PixiApplication or a TickerProvider\");\n }\n\n ticker.add(tickerCallback);\n onCleanup(() => {\n ticker.remove(tickerCallback);\n });\n};\n\nconst asyncDelay = async (ticker: Ticker, delayMs: number) => {\n let timeDelayed = 0;\n\n let resolvePromise: (value: void | PromiseLike<void>) => void;\n\n const promise = new Promise<void>((resolve) => {\n resolvePromise = resolve;\n });\n\n const internalCallback = () => {\n timeDelayed += ticker.deltaMS;\n if (timeDelayed < delayMs) return;\n resolvePromise();\n };\n\n ticker.add(internalCallback);\n\n await promise;\n\n ticker.remove(internalCallback);\n};\n\n/**\n * Create a delay function that waits until a given number of milliseconds has passed on the current Ticker context before resolving.\n *\n * This function must be called inside a `PixiApplication` or `TickerProvider` context.\n *\n * @returns An async function we can await to delay events in sync with time passed on the Ticker.\n *\n * Simply await for it to resolve in an async context.\n *\n * @note It will not resolve if the ticker is paused or stopped.\n *\n * @throws {Error} If called outside of a `PixiApplication` or `TickerProvider` context.\n */\nexport const createAsyncDelay = (): ((delayMs: number) => Promise<void>) => {\n const ticker = useContext(TickerContext);\n\n if (!ticker) {\n throw new Error(\n \"`createDelay` must be used within a PixiApplication or a TickerProvider. The returned `delay` function can be called in an async context but `createDelay` must be called in a synchronous scope within a PixiApplication or a TickerProvider\"\n );\n }\n const delayWithTicker = (delayMs: number) => asyncDelay(ticker, delayMs);\n\n return delayWithTicker;\n};\n\n/**\n * Runs a callback when a given number of milliseconds has passed on the ticker.\n *\n * It is guaranteed to be in sync with the shared ticker and uses accumulated deltaMs not an external time measurement.\n *\n * @param delayMs - Number of milliseconds to wait (measured in the ticker's time units).\n *\n * @param callback - A callback function that will fire when the delayMs time has passed.\n *\n * @throws {Error} If called outside of a `PixiApplication` or `TickerProvider` context.\n *\n * @note It will not run the callback if the ticker is paused or stopped.\n *\n */\nexport const delay = (delayMs: number, callback?: () => void): void => {\n const ticker = useContext(TickerContext);\n if (!ticker) {\n throw new Error(\n \"`createDelay` must be used within a PixiApplication or a TickerProvider. The returned `delay` function can be called in an async context but `createDelay` must be called in a synchronous scope within a PixiApplication or a TickerProvider\"\n );\n }\n\n let timeDelayed = 0;\n\n const internalCallback = () => {\n timeDelayed += ticker.deltaMS;\n if (timeDelayed < delayMs) return;\n callback?.();\n ticker.remove(internalCallback);\n };\n\n ticker.add(internalCallback);\n};\n"],"names":["PixiAppContext","createContext","TickerContext","getPixiApp","app","useContext","Error","PixiApplication","props","initialisationProps","splitProps","appResource","createResource","Application","init","autoDensity","resolution","Math","min","window","devicePixelRatio","sharedTicker","createEffect","ref","ticker","autoStart","start","onCleanup","destroy","children","_$createComponent","Show","when","Provider","value","TickerProvider","getTicker","onTick","tickerCallback","add","remove","asyncDelay","delayMs","timeDelayed","resolvePromise","promise","Promise","resolve","internalCallback","deltaMS","createAsyncDelay","delayWithTicker","delay","callback"],"mappings":";;;AAKA,MAAMA,iBAAiBC,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A,EACF;AACA,QAAM6C,kBAAkBA,CAACT,YAAoBD,WAAWjB,QAAQkB,OAAO;AAEvE,SAAOS;AACT;AAgBO,MAAMC,QAAQA,CAACV,SAAiBW,aAAgC;AACrE,QAAM7B,SAASnB,WAAWH,aAAa;AACvC,MAAI,CAACsB,QAAQ;AACX,UAAM,IAAIlB,MACR,+OACF;AAAA,EACF;AAEA,MAAIqC,cAAc;AAElB,QAAMK,mBAAmBA,MAAM;AAC7BL,mBAAenB,OAAOyB;AACtB,QAAIN,cAAcD,QAAS;AAC3BW,eAAAA;AACA7B,WAAOgB,OAAOQ,gBAAgB;AAAA,EAChC;AAEAxB,SAAOe,IAAIS,gBAAgB;AAC7B;"}
@@ -1,7 +1,7 @@
1
1
  export type { ContainerProps, LeafProps } from "./component-creation";
2
2
  export { onResize } from "./on-resize";
3
3
  export type { PixiApplicationProps } from "./pixi-application";
4
- export { delay, getPixiApp, getTicker, onTick, PixiApplication, TickerProvider, } from "./pixi-application";
4
+ export { createAsyncDelay, delay, getPixiApp, getTicker, onTick, PixiApplication, TickerProvider, } from "./pixi-application";
5
5
  export { PixiCanvas } from "./pixi-canvas";
6
6
  export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite, } from "./pixi-components";
7
7
  export type { PixiEventHandlerMap } from "./pixi-events";
@@ -1,5 +1,5 @@
1
- import type { ApplicationOptions, TickerCallback } from "pixi.js";
2
- import { Application, Ticker } from "pixi.js";
1
+ import type { ApplicationOptions, Ticker, TickerCallback } from "pixi.js";
2
+ import { Application } from "pixi.js";
3
3
  import type { JSX, ParentProps, Ref } from "solid-js";
4
4
  /**
5
5
  * A custom SolidJS hook to access the root PIXI.Application instance.
@@ -66,22 +66,31 @@ export declare const getTicker: () => Ticker;
66
66
  */
67
67
  export declare const onTick: (tickerCallback: TickerCallback<Ticker>) => void;
68
68
  /**
69
- * Delay until a given number of milliseconds has passed on the shared ticker.
69
+ * Create a delay function that waits until a given number of milliseconds has passed on the current Ticker context before resolving.
70
70
  *
71
- * It is guaranteed to be in sync with the shared ticker and uses accumulated deltaMs not an external time measurement.
71
+ * This function must be called inside a `PixiApplication` or `TickerProvider` context.
72
72
  *
73
- * Simply await for it to resolve if in an async context or pass in a callback function.
74
- * It's not recommended to use both techniques at once.
73
+ * @returns An async function we can await to delay events in sync with time passed on the Ticker.
75
74
  *
76
- * @param delayMs - Number of milliseconds to wait (measured in the ticker's time units).
75
+ * Simply await for it to resolve in an async context.
76
+ *
77
+ * @note It will not resolve if the ticker is paused or stopped.
78
+ *
79
+ * @throws {Error} If called outside of a `PixiApplication` or `TickerProvider` context.
80
+ */
81
+ export declare const createAsyncDelay: () => ((delayMs: number) => Promise<void>);
82
+ /**
83
+ * Runs a callback when a given number of milliseconds has passed on the ticker.
77
84
  *
78
- * @param callback - Optional callback function that will fire when the delayMs time has passed.
85
+ * It is guaranteed to be in sync with the shared ticker and uses accumulated deltaMs not an external time measurement.
86
+ *
87
+ * @param delayMs - Number of milliseconds to wait (measured in the ticker's time units).
79
88
  *
80
- * @returns A Promise that resolves once the ticker's time has advanced by `delayMs`.
89
+ * @param callback - A callback function that will fire when the delayMs time has passed.
81
90
  *
82
91
  * @throws {Error} If called outside of a `PixiApplication` or `TickerProvider` context.
83
92
  *
84
- * @note It will not resolve or fire the callback if the ticker is paused or stopped.
93
+ * @note It will not run the callback if the ticker is paused or stopped.
85
94
  *
86
95
  */
87
- export declare const delay: (delayMs: number, callback?: () => void) => Promise<void>;
96
+ export declare const delay: (delayMs: number, callback?: () => void) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pixi-solid",
3
3
  "private": false,
4
- "version": "0.0.21",
4
+ "version": "0.0.22",
5
5
  "description": "A library to write PixiJS applications with SolidJS",
6
6
  "author": "Luke Thompson",
7
7
  "license": "MIT",