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

3.1.0 Phaser.Physics.Arcade.Sprite Resizing Doesn't Work #3247

Closed
yigitozdemir opened this issue Feb 17, 2018 · 6 comments
Closed

3.1.0 Phaser.Physics.Arcade.Sprite Resizing Doesn't Work #3247

yigitozdemir opened this issue Feb 17, 2018 · 6 comments

Comments

@yigitozdemir
Copy link
Contributor

@yigitozdemir yigitozdemir commented Feb 17, 2018

Hi Everyone,

I am trying to move into Phaser 3.1.0, this is my very first step into Phaser 3. I initialized a scene using Arcade Physics, everything is working great but i can not resize Sprites.

create: function(){ this.physics.world.setBounds(0, 0, 400, 400); var star = this.physics.add.sprite(128, 128, 'star'); star.width = 20; star.height = 20; star.setGravity(40, 100); star.setBounce(1).setCollideWorldBounds(true); },

According to documentation width is defined as:

The native (un-scaled) width of this Game Object.

I think it is an issue about scaling game objecs.

Thanks every greate one in this great community!

@agilul
Copy link

@agilul agilul commented Feb 17, 2018

Use .displayWidth and .displayHeight (or the function .setDisplaySize(w,h)) to resize, as these will also adjust the sprite scale.

@yigitozdemir
Copy link
Contributor Author

@yigitozdemir yigitozdemir commented Feb 17, 2018

Oh thank you that worked.

But now, image and body moves seperately, https://i.hizliresim.com/bBLPdb.png
Modified code to this, but it didn't work:

create: function(){ this.physics.world.setBounds(0, 0, 400, 400); var star = this.physics.add.sprite(128, 128, 'star'); star.displayWidth = 20; star.displayHeight = 20; star.x = star.body.position.x; star.y = star.body.position.y; star.setGravity(40, 100); star.setBounce(1).setCollideWorldBounds(true); },

@agilul
Copy link

@agilul agilul commented Feb 17, 2018

Yeah it seems like the physics body doesn't correctly update after modifying the sprite scale.
Needs some checking on the calculations there.

EDIT: probably due to sprite having default pivot/anchor/origin at their center?

@yigitozdemir
Copy link
Contributor Author

@yigitozdemir yigitozdemir commented Feb 17, 2018

@agilul Thanks, with your comment, I discovered that, we need to set display origin 0 before resizing:

create: function(){ this.physics.world.setBounds(0, 0, 400, 400); var star = this.physics.add.sprite(128, 128, 'star'); star.displayOriginX = 0; star.displayOriginY = 0; star.displayWidth = 20; star.displayHeight = 20; star.x = 0; star.y = 0; star.setGravity(40, 100); star.setBounce(1).setCollideWorldBounds(true); },

I used to scale everything mathematically on my previous games, that will be hard to get used to for me.

@pixelpicosean
Copy link
Contributor

@pixelpicosean pixelpicosean commented Mar 1, 2018

The physics body align issue has been solved in PR #3300

@photonstorm
Copy link
Owner

@photonstorm photonstorm commented Mar 1, 2018

Sweet, thanks @pixelpicosean

@photonstorm photonstorm closed this Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants