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

createFromObjects() doesn't copy custom properties #6391

Closed
samme opened this issue Feb 17, 2023 · 11 comments · Fixed by #6488
Closed

createFromObjects() doesn't copy custom properties #6391

samme opened this issue Feb 17, 2023 · 11 comments · Fixed by #6488

Comments

@samme
Copy link
Contributor

samme commented Feb 17, 2023

Version

  • Phaser Version: 3.60.0-beta.18

Description

For example giving an Object a property of alpha: 0.5 in Tiled will be reflected in the Game Object that is created.

This happened in v3.55.2 but it doesn't happen now.

Example Test Code

https://labs.phaser.io/edit.html?src=src/3.60\tilemap\create%20from%20objects.js&v=3.60.0-beta.18

const coinObject = this.map.objects[0].objects[3];

console.assert(coinObject.properties.alpha === 0.25);

const [ coin ] = this.map.createFromObjects('Coin Object Layer', [
    { id: coinObject.id, key: 'coin' }
]);

console.assert(coin.alpha === 0.25, 'Coin sprite should have alpha 0.25 not %s', coin.alpha);
@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

@paxperscientiam
Copy link
Contributor

@photonstorm I guess the currently documented behavior is changing, then? Per new docs, "Custom object properties that do not exist as a Game Object property are set in the Game Objects data."

That said, an option to automatically update gameobject properties based on custom properties sounds great.

@samme
Copy link
Contributor Author

samme commented Apr 25, 2023

The correct behavior should be the same in v3.55 and v3.60. The incorrect behavior was in the some of the v3.60 betas only.

If you create a sprite from Tiled Object

{ alpha: 0.5, color: 'green' }

then the resulting sprite will have

alpha === 0.5
data.values.color === 'green'

Here color is the custom object property.

@paxperscientiam
Copy link
Contributor

paxperscientiam commented Apr 26, 2023

Thanks for underscoring that, @samme . I definitely misread it.

That said, I cannot get custom properties to have any effect. In my case, I'm creating game objects from a class that extends Physics.Matter.Image in this way:

        this.tileMap.createFromObjects("GameObjects/Ships", {
            name: "SimpleShip",
            scene: this,
            key: "ship",
            classType: SimpleShip,
        })

The corresponding "SimpleShip" entry in Tiled on the Tiled layer "GameObjects/Ships" is defined like this:
image

This works great, except for the custom properties issue.

Examining the data store ...
image

Only "alpha" and "color" show up. Alpha shouldn't even be there, if I understand you correctly. "dummy" should be there, but it's not.

gameObject.alpha, gameObject.flipX, and gameObject.flipY are the default values (1, false, false).

For completeness, I tried again without a custom class (I added to the aforementioned Tiled Layer an object named "LOL").

        const LOL = this.tileMap.createFromObjects("GameObjects/Ships", {
            name: "LOL",
            scene: this
        })

image

For the "LOL" object, all of the custom properties do show in the data store, including the ones that shouldn't (like alpha and scale).

Do you think there's an issue with my code, or perhaps there's a bug?

Thank you

Edit: i should add, I'm issuing the regular release of 3.60

@samme
Copy link
Contributor Author

samme commented Apr 26, 2023

For the "LOL" object, all of the custom properties do show in the data store, including the ones that shouldn't (like alpha and scale).

This is definitely in Phaser v3.60.0, not a beta? I can't think of why that would happen. In tilemap/create from objects alpha is working correctly (see dim coin at top).

@paxperscientiam
Copy link
Contributor

I just scrutinized "node_modules/phaser/package.json" and can confirm that package.json.version indicates as much.

image

I will try again from scratch with what you shared.

@photonstorm
Copy link
Collaborator

photonstorm commented Apr 27, 2023

I just scrutinized "node_modules/phaser/package.json" and can confirm that package.json.version indicates as much.

Check the browser Dev Tools. Phaser logs its version number to the console when it boots. For example, you may have npm at 3.60 but override it with a different package / script tag. Worth checking.

@paxperscientiam
Copy link
Contributor

paxperscientiam commented Apr 27, 2023

Indicated there too, I'm afraid.

image

To clarify, I'm using vite as my build tool; only mentioning it because the only hard coded script tag in my project is that which points to vite's bundle.

I'll try to see if I can replicate what I'm experiencing with a minimal setup.

@paxperscientiam
Copy link
Contributor

Hmm, I'm still getting unexpected results.

Tiled object:
image

image

image

I created a gist that will hopefully help anyone else reproduce what I'm seeing. 🤞

https://gist.github.com/paxperscientiam/c6a443d5315f2ce7b7e843c40353e073

@samme
Copy link
Contributor Author

samme commented Apr 28, 2023

@paxperscientiam I reproduced your problem. @photonstorm could you reopen?

@paxperscientiam
Copy link
Contributor

Thanks @samme

samme added a commit to samme/phaser that referenced this issue May 1, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants