⭐ Click here for special offer ⭐

Creating new plugin

Plugin looks like any other game module and it can contain any JavaScript code.

Here is basic syntax of Panda 2 plugin:

game.module(
    'plugin.example'
)
.body(function() {
    
// Insert JavaScript code here

});

Note that plugin name is also the path of the plugin file. For example plugin named plugin.example must be a file named example.js in a folder plugin

Example

Here is example plugin, that inject's new method into Rectangle class.

game.module(
    'plugin.example'
)
.require(
    'engine.geometry'
)
.body(function() {
    
game.Rectangle.inject({
    size: function() {
        return this.width * this.height;
    }
});

});

Then you would use that plugin in your game like this:

game.module(
    'game.main'
)
.require(
    'plugin.example'
)
.body(function() {
    
game.createScene('Main', {
    init: function() {
        var rect = new game.Rectangle(10, 20);
        console.log(rect.size()); // 200
    }
});

});