How do I check collision with a scaled tileSprite?

Hi! :slight_smile:

I saw this example the other day and I was wondering why it doesn’t work as expected if I try to scaled it down. :face_with_raised_eyebrow:

Look at this codepen for a quick understanting of my problem.

Any thoughts? :thinking:

For the static block, you are giving that game object a static body here: this.physics.add.existing(staticBlock, true);. When a game object has a static body, any time you make changes to the game object, you have to manually update that game objects body.

Reference: https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.StaticBody.html

Another solution is, you could give that game object a dynamic body and then update the setImmovable property, which will prevent the game object from moving.

Example:

this.physics.add.existing(staticBlock, false);
// doesn't work as expected if it is put here
staticBlock.setScale(0.5);
staticBlock.body.immovable = true;
2 Likes

Hi, @scottwestover, thanks a lot for the example that you offered! It worked! I also tried the first solution, but now it appears that the game can’t “see” the collision at all. I guesses that by

you mean using the staticBlock.refreshBody(); instruction as in this example.
Anyway, thanks again for your help! :slight_smile:

My mistake: I replaced

with staticBlock.body.updateFromGameObject(); and now both solutions work as intended. :blush:

1 Like