IApplication
Defined in: core/interfaces/IApplication.ts:68
Represents the core application interface, extending PixiJS Application. It manages plugins, game state, actions, and provides access to various application subsystems.
Template
Section titled “Template”The type of the data schema used by the application’s store.
Template
Section titled “Template”The type of the action context used for dispatching actions.
Template
Section titled “Template”The type of actions that can be dispatched in the application.
Example
Section titled “Example”import { Application } from '@dillpixel/framework';
// Define your data schema, action context, and actionsinterface MyDataSchema { score: number; playerName: string;}
interface MyActionContext { userId: string;}
type MyActions = 'startGame' | 'endGame' | 'updateScore';
// Create a new application instanceconst app = new Application<MyDataSchema, MyActionContext, MyActions>();
async function main() { await app.initialize({ // Application configuration appName: 'My Awesome Game', // ... other config options }, document.getElementById('game-container'));
// Access application properties and methods console.log(app.appName); // 'My Awesome Game' app.scenes.load('mainMenu'); app.action('startGame');}
main();
Extends
Section titled “Extends”Application
Properties
Section titled “Properties”actionContext
Section titled “actionContext”actionContext:
ActionContext
Defined in: core/interfaces/IApplication.ts:281
The current context for dispatching actions. Allows passing additional contextual information when actions are triggered.
Example
Section titled “Example”app.actionContext = { userId: 'user123', source: 'uiButton' };app.action('submitScore', { score: 1000 }); // Context will be included
readonly
anim: typeofgsap
Defined in: core/interfaces/IApplication.ts:483
The global GSAP instance.
Direct access to the gsap
object for creating tweens and timelines.
Returns
Section titled “Returns”The GSAP instance.
Example
Section titled “Example”app.anim.to(mySprite.scale, { x: 1.5, y: 1.5, duration: 0.5, ease: 'power2.inOut' });
animation
Section titled “animation”
readonly
animation:IGSAPPlugin
Defined in: core/interfaces/IApplication.ts:472
The GSAPPlugin instance for managing animations. Provides access to GSAP functionality and animation contexts.
Returns
Section titled “Returns”The GSAP plugin instance.
Example
Section titled “Example”const timeline = app.animation.createTimeline();timeline.to(mySprite, { alpha: 0, duration: 1 });
appName
Section titled “appName”
readonly
appName:string
Defined in: core/interfaces/IApplication.ts:353
The name of the application. Defined in the application configuration.
Example
Section titled “Example”document.title = app.appName;
appVersion
Section titled “appVersion”
readonly
appVersion:string
|number
Defined in: core/interfaces/IApplication.ts:364
The version of the application.
Typically injected at build time (e.g., via __DILL_PIXEL_APP_VERSION
).
Example
Section titled “Example”console.log(`Running ${app.appName} v${app.appVersion}`);
assets
Section titled “assets”
readonly
assets:IAssetsPlugin
Defined in: core/interfaces/IApplication.ts:142
The AssetsPlugin instance for managing game assets. Provides methods for loading and accessing textures, sounds, fonts, etc.
Example
Section titled “Example”const playerTexture = await app.assets.load('playerSprite');const backgroundMusic = app.assets.getSound('bgm');
readonly
audio:IAudioManagerPlugin
Defined in: core/interfaces/IApplication.ts:210
The AudioManagerPlugin instance for managing game audio. Handles sound effects and background music.
Example
Section titled “Example”app.audio.playSound('explosion');app.audio.setMusicVolume(0.7);
center
Section titled “center”
readonly
center:Point
Defined in: core/interfaces/IApplication.ts:119
The center point (x, y) of the application’s view/canvas. Automatically updated when the application resizes.
Example
Section titled “Example”// Center a sprite on the screenmySprite.position.copyFrom(app.center);
config
Section titled “config”
readonly
config:Partial
<AppConfig
>
Defined in: core/interfaces/IApplication.ts:81
The application configuration object. Contains settings for various aspects of the application, including plugins, assets, and scenes.
Example
Section titled “Example”console.log(app.config.appName); // 'My Awesome Game'if (app.config.showStats) { // Show performance stats}
controls
Section titled “controls”
readonly
controls:IControls
Defined in: core/interfaces/IApplication.ts:247
The Controls instance, typically accessed via the InputPlugin. Provides a higher-level abstraction for game controls and actions.
Example
Section titled “Example”if (app.controls.isActionActive('jump')) { // Player jumps}
readonly
data:IDataAdapter
Defined in: core/interfaces/IApplication.ts:270
The primary DataAdapter instance, usually for managing game data.
Example
Section titled “Example”const playerData = await app.data.get('playerStats');await app.data.set('playerStats', { health: 100, mana: 50 });
readonly
env:Record
<string
,string
>
Defined in: core/interfaces/IApplication.ts:95
Environment variables available to the application.
Typically sourced from import.meta.env
.
Example
Section titled “Example”const apiKey = app.env.API_KEY;if (app.env.NODE_ENV === 'development') { // Enable debug features}
readonly
exec:ICoreFunctions
Defined in: core/interfaces/IApplication.ts:395
Alias for func
. Access to core application functions.
readonly
focus:IFocusManagerPlugin
Defined in: core/interfaces/IApplication.ts:188
The FocusManagerPlugin instance for managing UI focus.
readonly
func:ICoreFunctions
Defined in: core/interfaces/IApplication.ts:389
Access to core application functions. Provides a registry for globally accessible utility functions.
Example
Section titled “Example”const utility = app.func.get('myUtility');if (utility) utility.doSomething();
readonly
i18n:Ii18nPlugin
Defined in: core/interfaces/IApplication.ts:221
The i18nPlugin instance for internationalization and localization.
Example
Section titled “Example”const localizedGreeting = app.i18n.translate('GREETING_KEY');app.i18n.setLocale('fr-FR');
readonly
input:IInputPlugin
Defined in: core/interfaces/IApplication.ts:234
The InputPlugin instance for managing various input sources. This often consolidates controls from keyboard, mouse, gamepad, etc.
keyboard
Section titled “keyboard”
readonly
keyboard:IKeyboardPlugin
Defined in: core/interfaces/IApplication.ts:182
The KeyboardPlugin instance for managing keyboard input.
Example
Section titled “Example”if (app.keyboard.isKeyDown('Space')) { // Player jumps}app.keyboard.onKeyDown.connect((keyEvent) => { if(keyEvent.key === 'Escape') app.scenes.load('pauseMenu');});
manifest
Section titled “manifest”
readonly
manifest:undefined
|string
|AssetsManifest
Defined in: core/interfaces/IApplication.ts:130
The asset manifest used by the application. Can be a URL to a manifest file, or an AssetsManifest object.
Example
Section titled “Example”console.log(app.manifest); // Could be './assets.json' or an object
onPause
Section titled “onPause”onPause:
Signal
<() =>void
>
Defined in: core/interfaces/IApplication.ts:293
A signal that emits when the application is paused.
Example
Section titled “Example”app.onPause.connect(() => { console.log('Application paused'); // Stop game-specific timers or animations not handled by app.pause()});
onResume
Section titled “onResume”onResume:
Signal
<() =>void
>
Defined in: core/interfaces/IApplication.ts:305
A signal that emits when the application is resumed from a paused state.
Example
Section titled “Example”app.onResume.connect(() => { console.log('Application resumed'); // Restart game-specific timers or animations});
paused
Section titled “paused”
readonly
paused:boolean
Defined in: core/interfaces/IApplication.ts:342
Indicates whether the application is currently paused.
Example
Section titled “Example”if (app.paused) { // Show pause menu}
popups
Section titled “popups”
readonly
popups:IPopupManagerPlugin
Defined in: core/interfaces/IApplication.ts:198
The PopupManagerPlugin instance for managing pop-up dialogs or views.
Example
Section titled “Example”app.popups.show('settingsPopup', { volume: 0.5 });
resizer
Section titled “resizer”
readonly
resizer:IResizerPlugin
Defined in: core/interfaces/IApplication.ts:227
The ResizerPlugin instance for managing application resizing.
scenes
Section titled “scenes”
readonly
scenes:ISceneManagerPlugin
Defined in: core/interfaces/IApplication.ts:154
The SceneManagerPlugin instance for managing game scenes. Handles scene transitions, loading, and lifecycle.
Example
Section titled “Example”app.scenes.load('level1');app.scenes.currentScene.pause();
signal
Section titled “signal”
readonly
signal:ICoreSignals
Defined in: core/interfaces/IApplication.ts:377
Access to core application signals. These are global signals for important application events.
Example
Section titled “Example”app.signal.onLoadRequiredComplete.connectOnce(() => { console.log('Core assets loaded!');});
readonly
size:Size
Defined in: core/interfaces/IApplication.ts:107
The current size (width and height) of the application’s view/canvas. Managed by the ResizerPlugin.
Example
Section titled “Example”console.log(app.size.width, app.size.height);const aspectRatio = app.size.width / app.size.height;
readonly
store:IStore
Defined in: core/interfaces/IApplication.ts:259
The Store instance for managing application state. Uses a data schema and adapters for persistence.
Example
Section titled “Example”const currentScore = app.store.getState().score;app.store.updateState({ score: currentScore + 10 });
webEvents
Section titled “webEvents”
readonly
webEvents:IWebEventsPlugin
Defined in: core/interfaces/IApplication.ts:167
The WebEventsPlugin instance for managing browser-related events. Handles events like window resize, visibility change, etc.
Example
Section titled “Example”app.webEvents.onResize.connect((newSize) => { console.log('Resized to:', newSize.width, newSize.height);});
Methods
Section titled “Methods”action()
Section titled “action()”action<
TActionData
>(action
,data?
):void
Defined in: core/interfaces/IApplication.ts:432
Dispatches an action with optional data.
This is an alias for sendAction
.
Type Parameters
Section titled “Type Parameters”TActionData
Section titled “TActionData”TActionData
= any
The type of data being sent.
Parameters
Section titled “Parameters”action
Section titled “action”The action type to dispatch.
TActionData
Optional data to accompany the action.
Returns
Section titled “Returns”void
Example
Section titled “Example”// Dispatch 'startGame' actionapp.action('startGame');
// Dispatch 'updateScore' action with dataapp.action('updateScore', { points: 100 });
actions()
Section titled “actions()”actions<
TActionData
>(action
):ActionSignal
<TActionData
>
Defined in: core/interfaces/IApplication.ts:415
Retrieves an ActionSignal for a specific action type. This allows subscribing to specific actions dispatched within the application.
Type Parameters
Section titled “Type Parameters”TActionData
Section titled “TActionData”TActionData
= any
The type of data expected with the action.
Parameters
Section titled “Parameters”action
Section titled “action”The action type to get the signal for.
Returns
Section titled “Returns”ActionSignal
<TActionData
>
An ActionSignal that can be connected to.
Example
Section titled “Example”// Assuming 'updateScore' is an action defined in 'MyActions'// And it carries a payload like { points: number }interface ScoreUpdateData { points: number; }
app.actions<ScoreUpdateData>('updateScore').connect((data) => { console.log(`Score updated by ${data.points} points.`); // Update game state based on data.points});
addAnimation()
Section titled “addAnimation()”addAnimation(
animation
,contextId?
):Tween
|Timeline
| (Tween
|Timeline
)[]
Defined in: core/interfaces/IApplication.ts:502
Adds one or more GSAP tweens or timelines to a specified animation context.
This refers to the GSAPPlugin’s custom animation context (a Set of tweens/timelines),
NOT a gsap.Context
instance. If no contextId is provided, animations are added
to the plugin’s global collection, allowing them to be managed (e.g., paused, resumed, killed) collectively.
Parameters
Section titled “Parameters”animation
Section titled “animation”A single GSAP tween/timeline or an array of them.
Tween
| Timeline
| (Tween
| Timeline
)[]
contextId?
Section titled “contextId?”string
Optional ID of the animation context. Defaults to the global context.
Returns
Section titled “Returns”Tween
| Timeline
| (Tween
| Timeline
)[]
The animation(s) that were added.
Example
Section titled “Example”const myTween = app.anim.to(myObject, { x: 100, duration: 1 });app.addAnimation(myTween, 'mySceneAnimationCollection');
// Later, kill all animations in this contextapp.animation.killAll('mySceneAnimationCollection'); // Assuming killAll is the method to clear the custom context
eases()
Section titled “eases()”eases(
namesOnly?
):string
[] |Eases
Defined in: core/interfaces/IApplication.ts:523
Returns the registered GSAP eases or their names. Useful for dynamically applying easing functions or listing available eases.
Parameters
Section titled “Parameters”namesOnly?
Section titled “namesOnly?”boolean
If true, returns only the ease names as an array of strings. Otherwise, returns an object mapping names to Ease functions.
Returns
Section titled “Returns”string
[] | Eases
An object of registered eases (name: Ease function) or an array of ease names.
Example
Section titled “Example”const availableEaseNames = app.eases(true); // ['power1.inOut', 'back.out', ...]console.log(availableEaseNames);
const easeFunctions = app.eases();if (easeFunctions['power2.in']) { app.anim.to(mySprite, { y: 200, ease: easeFunctions['power2.in'] });}
getPlugin()
Section titled “getPlugin()”getPlugin<
T
>(name
,debug?
):T
Defined in: core/interfaces/IApplication.ts:583
Retrieves a registered plugin by its name.
Type Parameters
Section titled “Type Parameters”T
extends IPlugin
<any
>
The expected type of the plugin.
Parameters
Section titled “Parameters”string
The name/ID of the plugin to retrieve.
debug?
Section titled “debug?”boolean
If true and the plugin is not found, an error will be logged. Defaults to false.
Returns
Section titled “Returns”T
The plugin instance if found, otherwise undefined (or T if type assertion is used).
Example
Section titled “Example”const myCustomPlugin = app.getPlugin<MyCustomPluginType>('myCustomPlugin');if (myCustomPlugin) { myCustomPlugin.doSomethingCool();}
const nonExistentPlugin = app.getPlugin('nonExistent', true); // Will log an error
initialize()
Section titled “initialize()”initialize(
config
,el?
):Promise
<Application
>
Defined in: core/interfaces/IApplication.ts:547
Initializes the application with the given configuration and attaches it to an HTML element. This is the main entry point for starting the application.
Parameters
Section titled “Parameters”config
Section titled “config”Partial
<AppConfig
>
The application configuration object.
HTMLElement
The HTML element to append the application’s canvas to. If not provided, an error will be thrown.
Returns
Section titled “Returns”Promise
<Application
>
A promise that resolves with the initialized application instance.
Example
Section titled “Example”const gameContainer = document.getElementById('game');if (gameContainer) { app.initialize({ appName: 'My Game' }, gameContainer) .then(initializedApp => { console.log(`${initializedApp.appName} initialized successfully!`); initializedApp.scenes.load('mainMenu'); }) .catch(error => console.error('Initialization failed:', error));} else { console.error('Game container element not found!');}
isActionActive()
Section titled “isActionActive()”isActionActive(
action
):boolean
Defined in: core/interfaces/IApplication.ts:458
Checks if a specific action is currently considered active, usually based on input controls.
Parameters
Section titled “Parameters”action
Section titled “action”The action type to check.
Returns
Section titled “Returns”boolean
True if the action is active, false otherwise.
Example
Section titled “Example”if (app.isActionActive('moveForward')) { player.move(1);}
pause()
Section titled “pause()”pause(
config?
):void
Defined in: core/interfaces/IApplication.ts:320
Pauses the application.
This can include pausing the ticker, animations, audio, and timers based on the PauseConfig
.
Parameters
Section titled “Parameters”config?
Section titled “config?”Optional configuration for what aspects of the application to pause.
Returns
Section titled “Returns”void
Example
Section titled “Example”// Pause everythingapp.pause();
// Only pause audio and timersapp.pause({ pauseAudio: true, pauseTimers: true });
postInitialize()
Section titled “postInitialize()”postInitialize():
Promise
<void
>
Defined in: core/interfaces/IApplication.ts:565
Runs any post-initialization setup tasks.
This is called after the main initialize
method has completed and core plugins are ready.
It’s a good place for plugins to finalize their setup or for the application to perform tasks
that depend on a fully initialized environment.
Returns
Section titled “Returns”Promise
<void
>
A promise that resolves when post-initialization tasks are complete.
Example
Section titled “Example”// Inside a custom Application class or after app.initialize resolvesasync function startMyGame() { await app.initialize(config, el); await app.postInitialize(); // Ensures everything is fully set up app.scenes.load('intro');}
resume()
Section titled “resume()”resume():
void
Defined in: core/interfaces/IApplication.ts:330
Resumes the application from a paused state. Restores the state of ticker, animations, audio, and timers that were paused.
Returns
Section titled “Returns”void
Example
Section titled “Example”app.resume();
sendAction()
Section titled “sendAction()”sendAction<
TActionData
>(action
,data?
):void
Defined in: core/interfaces/IApplication.ts:445
Dispatches an action with optional data.
Type Parameters
Section titled “Type Parameters”TActionData
Section titled “TActionData”TActionData
= any
The type of data being sent.
Parameters
Section titled “Parameters”action
Section titled “action”The action type to dispatch.
TActionData
Optional data to accompany the action.
Returns
Section titled “Returns”void
Example
Section titled “Example”// Dispatch 'playerAction' with specific detailsapp.sendAction('playerAction', { type: 'shoot', targetId: 'enemy123' });
setContainer()
Section titled “setContainer()”setContainer(
container
):void
Defined in: core/interfaces/IApplication.ts:596
Sets the main HTML container element for the application. This is typically the element where the PixiJS canvas is appended.
Parameters
Section titled “Parameters”container
Section titled “container”HTMLElement
The HTMLElement to be used as the application container.
Returns
Section titled “Returns”void
Example
Section titled “Example”const newGameContainer = document.createElement('div');document.body.appendChild(newGameContainer);app.setContainer(newGameContainer); // If app needs to change its parent container