Load External Script
Demonstrates how to load an external JavaScript file and access its global functions within a scene.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.script('fractals', 'assets/loader-tests/fractals.js');
}
create ()
{
const texture = this.textures.createCanvas('julia', 800, 600);
// These functions are all loaded in the fractals.js script file
// drawMandelbrot(texture.canvas, texture.context, 64);
// drawBurningShipFractal(texture.canvas, texture.context, 64);
drawJulia(texture.canvas, texture.context, 100);
// Call this if running under WebGL, or you'll see nothing change
texture.refresh();
this.add.image(400, 300, 'julia');
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
width: 800,
height: 600,
backgroundColor: '#000',
scene: Example
};
const game = new Phaser.Game(config);