Loading External Plugins
This example demonstrates how to load an external JavaScript plugin file during the preload phase and access its custom methods within a Scene.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.plugin('RandomNamePlugin', 'assets/loader-tests/RandomNamePlugin.js', true);
}
create ()
{
let plugin = this.plugins.get('RandomNamePlugin');
let names = plugin.getNames(10);
this.add.text(10, 10, names, { font: '16px Courier', fill: '#00ff00' });
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
width: 800,
height: 600,
scene: Example
};
let game = new Phaser.Game(config);