PhaserEditor2D / PhaserEditor

A friendly IDE to develop HTML5 games based on the Phaser framework.
https://phasereditor2d.com
Eclipse Public License 1.0
327 stars 45 forks source link

Optional parameters in constructor not generated as optional when extending class. #117

Closed bfountaine closed 5 years ago

bfountaine commented 5 years ago

Version

Description

I created a new phaser project, using typescript as the language. I opted to have the demo assets included. I created a new prefab, exactly the same as the 'dino' one already there, flipped the image on the vertical axis then added my new pre-fab to the Level.canvas by dragging and dropping it onto the canvas. On saving the canvas I now get an error in my Level.ts file:

Expected 5 arguments, but got 3.

In the generated code where it instantiates the new Dino prefab, it only passes in 3 arguments. In the original Dino.ts file, the last 2 parameters (aKey and aFrame) in the constructor are optional but in my newly created Dino2.tx file, the paramaters don't have the ? next to them, making them required.

If I look at Phaser.Sprite, those parameters are optional there too, so should be optional in the generated code. Just to test it further, I opened the Dino.canvas of the original Dino, moved him a bit them moved him back, when I saved, the newly generated code for that file also has the parameters as required now (ie without the ?):

constructor(aGame : Phaser.Game, aX : number, aY : number, aKey : any, aFrame : any) { super(aGame, aX, aY, aKey || 'dino', aFrame == undefined || aFrame == null? 0 : aFrame); var _anim_walk = this.animations.add('walk', [8, 9, 10, 11], 6, true); var _anim_stay = this.animations.add('stay', [0, 1, 2], 4, true); var _anim_jump = this.animations.add('jump', [4, 5], 4, true); _anim_stay.play();

Possible solution

PhaserEditor2D commented 5 years ago

Hi @bfountaine

I can reproduce the error. It is a regression in the Canvas compiler. Please, download the file I attach here (phasereditor.canvas.core_1.5.3.20181107.jar) and copy (replace) it in the plugins folder of the Phaser Editor installation folder. It contains a patch with the fix. Then, open the editor by clicking the file DebugPhaserEditor.bat, that is present in the root folder of the installation.

patch-1.zip

Please, try and tell us if it fixes the problem, to include the change in the next release of v1.

bfountaine commented 5 years ago

Hi

Yes, this has fixed it for me, thanks