Hi, i’ve got trouble for using plugin.
I’ve started a new project and testing the plugin. I use the phaser-3-template and the phaser-3-basePlugin.
I’ve got the error message :
Invalid Plugin: basePlugin
my code is :
import Phaser from “phaser”;
import logoImg from “./assets/logo.png”;
//import basePlugin from “./BasePlugin.min.js”;
const config = {
type: Phaser.AUTO,
parent: "phaser-example",
width: 800,
height: 600,
scene: {
preload: preload,
create: create
}
};
const game = new Phaser.Game(config);
function preload() {
this.load.image("logo", logoImg);
this.load.plugin('basePlugin', 'basePlugin.js');
}
function create() {
const logo = this.add.image(400, 150, "logo");
this.plugins.install('basePlugin');
console.log(this.plugins);
this.tweens.add({
targets: logo,
y: 450,
duration: 2000,
ease: "Power2",
yoyo: true,
loop: -1
});
}
Try adding a pack
object to your scene object in your config like so:
const config = {
type: Phaser.AUTO,
parent: "phaser-example",
width: 800,
height: 600,
scene: {
preload: preload,
create: create,
pack: {
files: [
{ type: 'scenePlugin', key: 'basePlugin', url: 'basePlugin.js' }
]
}
}
};
1 Like
thanks for your answer @Jake.Caron, but i have the same error thing
It looks like your implementation differs from the docs for installing the plugin. Try reading over this again and implement it the same way: https://github.com/photonstorm/phaser3-plugin-template.
I noticed that your using this.plugins.install
instead of this.sys.install
. You are also missing the following in your config:
plugins: [ 'BasePlugin' ],
map: {
'base': 'base'
}
You can start the plugin via adding true
at 3rd parameter of scene.load.plugin
method :
scene.load.plugin('basePlugin', 'basePlugin.js', true);
Therefore you don’t need to install it later.
To get plugin instance back, use
var pluginInst = scene.plugins.get('basePlugin');
I forgot to mention that i use the last version of phaser (3.18.0). I find a way that look to working but i need to change the code in the plugin for make it work. For those who struggle with creating plugin for phaser >3.0.8
i share my fork version of the base-plugin-phaser-3
just take, the BasePlugin.js in the dist folder.
1 Like