rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.21k stars 261 forks source link

RexBoardPlugin: Custom class constructor error #193

Closed meetpatel1989 closed 3 years ago

meetpatel1989 commented 3 years ago

Installed the board plugin through npm and loading the plugin in the game config file. I'm getting the board class when I print the class in the console but when I'm trying to define the class like in this demo it is not working.

import RexBoardPlugin from 'phaser3-rex-plugins/plugins/board-plugin.js';
plugins: {
        scene: [{
            key: 'rexBoard',
            plugin: RexBoardPlugin,
            mapping: 'rexBoard'
        },
            // ...
        ]
    }
//Added in create function of scene class
this.board = new Board(this, config);

//Outside scene class
class Board extends RexPlugins.Board.Board {
    constructor(scene, config) {
        // create board
        super(scene, config);
    }
}

The game failed to load with the following error Uncaught TypeError: Class constructor Board cannot be invoked without 'new'

image

The error points to the constructor line of the Board class.

rexrainbow commented 3 years ago

I did not add type define of RexPlugins.Board.xxx, (have no idea how to add type define of global variable)

Please try import Board class from 'phaser3-rex-plugins/plugins/board-components.js'. See this test code

meetpatel1989 commented 3 years ago

Thanks for the quick reply but I'm still getting the same error after importing board class from components as you have mentioned.

image

Sorry for the inconvenience.

rexrainbow commented 3 years ago

Perhaps it is an issue of typescript config, see this discussion thread.

meetpatel1989 commented 3 years ago

@rexrainbow Thanks for the hint. It worked. I really appreciate your help.