You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when use dom with physics, and Scale mode is Phaser.Scale.ScaleModes.FIT. the body size is not correct.
The problem can be solved by manually calling body.setSize.
To resolve the issue with Arcade.Body size when using ScaleModes.FIT, modify the create method in your scene to call body.setSize after adding the DOM element to the physics system. This ensures the body size is correctly set. Here is the updated code:
create(){this.cursors=this.input.keyboard.createCursorKeys();this.element=this.add.dom(300,200,'div','font-size: 96px','💩').setOrigin(0);this.physics.add.existing(this.element,false);this.element.body.setCollideWorldBounds(true);this.element.body.setSize(this.element.width,this.element.height);// Add this lineconstelement=this.add.dom(100,100,'div','font-size: 96px','💩').setOrigin(0);this.physics.add.existing(element,false);element.body.setCollideWorldBounds(true).setSize(element.width,element.height);}
This ensures the body size is correctly set when using ScaleModes.FIT.
Version
Phaser Version: 3.80.1
Operating system: Windows 10
Browser: Edge , Chrome
Description
when use dom with physics, and Scale mode is Phaser.Scale.ScaleModes.FIT. the body size is not correct.
The problem can be solved by manually calling body.setSize.
Example Test Code
sandbox
The text was updated successfully, but these errors were encountered: