Interface: ApplicationPlugin
Defined in: node_modules/pixi.js/lib/app/Application.d.ts:59
Interface for creating Application plugins. Any plugin that's usable for Application must implement these methods.
To create a plugin:
- Create a class that implements this interface
- Add the required static extension property
- Register the plugin using extensions.add()
Example
import { ApplicationPlugin, ExtensionType, extensions } from 'pixi.js';
class MyPlugin {
// Required: Declare the extension type
public static extension = ExtensionType.Application;
// Required: Implement init method
public static init(options: Partial<ApplicationOptions>): void {
// Add properties/methods to the Application instance (this)
Object.defineProperty(this, 'myFeature', {
value: () => console.log('My feature!'),
});
// Use options if needed
console.log('Plugin initialized with:', options);
}
// Required: Implement destroy method
public static destroy(): void {
// Clean up any resources
console.log('Plugin destroyed');
}
}
// Register the plugin
extensions.add(MyPlugin);
// Usage in application
const app = new Application();
await app.init();
app.myFeature(); // Output: "My feature!"
> [!IMPORTANT]
> - Plugins are initialized in the order they are added
> - Plugins are destroyed in reverse order
> - The this context in both methods refers to the Application instance
See
- ExtensionType For different types of extensions
- extensions For the extension registration system
- ApplicationOptions For available application options
Advanced
Methods
destroy()
> destroy(): void
Defined in: node_modules/pixi.js/lib/app/Application.d.ts:67
Called when destroying Application, scoped to Application instance.
Returns
void
init()
> init(options): void
Defined in: node_modules/pixi.js/lib/app/Application.d.ts:65
Called when Application is constructed, scoped to Application instance.
Passes in options as the only argument, which are Application init() options.
Parameters
options
Partial<ApplicationOptions>
Application options.
Returns
void