Jump to content

Using Plugins


Recommended Posts

Hi, I hesitated to create the same post couple of days ago. I was also sad that there isn't so much doc about plugins in Phaser.


I was trying to use the Juicy plugin from the Phaser plugin repository. (https://github.com/photonstorm/phaser-plugins/tree/master/Juicy)

So i did like this :
var GameState = {    create: function(){      // rest of the code      this.juicy = this.game.plugins.add(new Phaser.Plugin.Juicy(this));    },    gameOver: function(bomb){     // when I need to call my plugin      this.juicy.shake();    }};

PS: Pro tip : Don't forget to add the plugin script <script src="Juicy.js"></script>


EDIT : Pro tip 2 : of course the use of this depend if you're using the OOP notation and game states and all that stuff. Try to play with the this value and console.log()


Pro tip 3 : I'm not a pro ;)


Link to comment
Share on other sites


That's all super useful. Thanks.


Zaidar, can you confirm that the example you gave above re: the use of the juicy plugin is the appropriate approach? i.e.

this.juicy = this.game.plugins.add(new Phaser.Plugin.Juicy(this));


And ... did you get the Juicy plugin working? Do you by any chance have an example? Just wondered .....


Thanks again for replying, all very helpful.




Link to comment
Share on other sites

Well, since it works and the plugin is part of the game.plugins array, I think that's the good solution.I have an example working for you. Let me put this online.


Here is the game, the only part I use the Juicy plugin is for the screenShake effect (I know, but it was just for testing at first, so I just left it here)




This is the source on Github :





Basically if you look at line 57, I'm adding the plugin into the Phaser pluginManager.

And lines 157 and 169 I use the shake() function to make the screen shake.

At the end, when you put a red bomb on the black container, it explodes and make the screen shakes.




If you have already used OOP for your games, like a Player.js where you define a player "constructor" and player functions, this is the same thing. Plugins could just be inserted in the main code, but at the end of the day, it's just for better clarity and organisation I think.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...