Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TexturePacker default origin of frames #288

Open
davyzhang opened this issue Jul 7, 2023 · 4 comments
Open

TexturePacker default origin of frames #288

davyzhang opened this issue Jul 7, 2023 · 4 comments
Labels
Enhancement New feature or request

Comments

@davyzhang
Copy link

Version

  • Phaser Editor 2D Version: 3.62.1
  • Operating System: windows
  • Web Browser and version:
    all-in-one editor

Description

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
Copy link
Author

something wrong with my picture indeed, sorry for the issue

@PhaserEditor2D
Copy link
Owner

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
Copy link
Author

davyzhang commented Jul 7, 2023

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
Copy link
Owner

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!

@PhaserEditor2D PhaserEditor2D reopened this Jul 7, 2023
@PhaserEditor2D PhaserEditor2D changed the title setting origin to 0.5 in prefab is not working TexturePacker default origin of frames Jul 7, 2023
@PhaserEditor2D PhaserEditor2D added the Enhancement New feature or request label Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants