I’m using Phaser 3 with Arcade Physics and I use tilemaps so to recreate the sprites I use the createFromObjects() function.
The problem is this function returns a list of sprites without physics, the same thing that when you do this.add.sprite() (without .physics) and I need the setVelocityX() function.
Since you are setting the enemy’s velocity, that means they should be created with dynamic bodies, which is the default behavior when no second parameter is provided to the enable method.
I have a similar problem. I’m able to add a body with this.physics.world.enable(this.checkpoints,0); but even after this there is no enableBody or disableBody functions in the Sprite (since it’s still not an ArcadeSprite). I’m trying to make overlap handler that uses disableBody can’t find any way around this annoying problem. Can I make those functions available or is there a workaround to doing disableBody?
I don’t think there’s any way to make an Arcade.Sprite from createFromObjects(). It only makes ordinary Sprites. You can add bodies to them but they won’t have the Arcade Physics components like enableBody(), disableBody().
You could copy the components you want into those Sprites manually.
Methods like setVelocityX() have an equivalent on the body so you can use that instead.
Thank you, seems like physics.world.enable should do that copying, but since it doesn’t, I ended looking what disableBody does and just copying the necessary lines to where I need them. Seems to work well.