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

Comments

4 participants
@yigitozdemir
Contributor

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Contributor

pixelpicosean commented Mar 1, 2018

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

@photonstorm

This comment has been minimized.

Owner

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