hey, has anybody been able to run Samme’s FollowPlugin with npm/ES6 setup? i’ve been able to install it from a local copy, but Phaser doesn’t recognize the following
this.follow.add etc. Cannot read property ‘add’ of undefined
How did you add/install the plugin?
thanks for the reply samme,
i tried to install it from github with:
npm install https://github.com/samme/phaser-plugin-follow.git
and:
npm install --save https://github.com/samme/phaser-plugin-follow.git
also tried both of the above with the SSH link, and any variant that i could find online.
finally i downloaded the master as a zip, unzipped it, and used npm to install from the local folder.
my config.js file plugins section looks like this:
plugins: {
scene: [
{
plugin: PhaserMatterCollisionPlugin, // The plugin class
key: "matterCollision",
mapping: "matterCollision"
},
{
plugin: Phaser.Plugins.FollowPlugin,
key: 'FollowPlugin',
mapping: 'follow'
}
]
}
and this code is in my player.js file, which is instantiated by SceneLevel_1:
this.scene.follow.add(follower, {
target: objectB,
offsetX: 0,
offsetY: 0,
rotate: false,
rotateOffset: false });
i’ve debugged everything including ‘this.scene’, so somehow i’m not finding the plugin with the last code bit.
any idea what i’m missing here?
I tried it with npm install https://github.com/samme/phaser-plugin-follow.git
and it worked well.
- Import the plugin.
import FollowPlugin from 'phaser-plugin-follow'
- Set it up.
plugins: {
scene: [
{
key: 'FollowPlugin',
plugin: FollowPlugin,
start: true,
mapping: 'follow'
}
]
},
- Use it
// the red rectangle will follow my player
let rect = this.add.rectangle(10, 10, 20, 20, 0xff0000)
this.follow.add(rect, {
target: this.player,
offsetX: 0,
offsetY: 0,
rotate: false,
rotateOffset: false
})
thanks to both samme and yannick. i got the plugin to work by using the correct import statement, great stuff!!! but i still can’t install the plugin with node.js/npm, but i’m sure that’s just because i don’t have a thorough knowledge of npm and github, so i’ll hit the books.
thanks again