PhaserEditor2D / PhaserEditor2D-v3

A web-based IDE for HTML5 game development. Powered by Phaser.
https://phasereditor2d.com
MIT License
426 stars 57 forks source link

TexturePacker default origin of frames #288

Open davyzhang opened 1 year ago

davyzhang commented 1 year ago

Version

Changing a image object's origin inside the prefab doesn't generate corresponding code, it looks being ignored. But it can display correctly in the editor. This only happens when set the origin to 0.5, if it is set to other values , code will be generated correctly

Possible solution

manually add the code

image

code generated like this:

    constructor(scene: Phaser.Scene, x?: number, y?: number) {
        super(scene, x ?? 0, y ?? 0);

        // cardBackBig_png
        const cardBackBig_png = scene.add.image(0, 0, "gaple", "cardBackBig.png");
        cardBackBig_png.setOrigin(0, 0);
        this.add(cardBackBig_png);

        // dotTop
        const dotTop = scene.add.image(20, 20, "gaple", "dot2big.png");
        this.add(dotTop);

        // dotDown
        const dotDown = scene.add.image(20, 60, "gaple", "dot1big.png");
        this.add(dotDown);

        this.dotTop = dotTop;
        this.dotDown = dotDown;

        /* START-USER-CTR-CODE */
        // Write your code here.

        /* END-USER-CTR-CODE */
    }
davyzhang commented 1 year ago

something wrong with my picture indeed, sorry for the issue

PhaserEditor2D commented 1 year ago

Hi! I'm glad you solved the issue. 0.5 is the default origin in images and sprites, for that reason the editor doesn't generate code for it.

davyzhang commented 1 year ago

Thank you so much for your excellent work! I think its better to post the finding here in case someone meets the same problem.

The reason is the tool texturepacker gui set the origin as 0,0 by default for every frame inside the json file. PhaserEditor2d does a very good job to respect this value and render it correctly in the first place.

And the problem is, if I set it back to 0.5,0.5 in the editor, No code will be generated to correct this value, so in the phaser side, it would still be 0,0 as the texture packer indicates.

The easy way to fix is just toggle off the option of texture packer to let phaser decide the origin.

PhaserEditor2D commented 1 year ago

Oh! I see. Yes, because in that case, 0.5 is not the default value in Phaser, but it is in the editor. It could be a bit complicated to handle these cases. Maybe I should provide the option of forcing the editor always to generate the origin for certain objects. I'm re-opening the issue.

Thanks for the kind words!