Hello,
I would like to build a game with juste basic geometrical shapes, thus not having to import images.
Is there a way to do this properly with phaser 3 ?
I have attempted something like this:
const rectangle = scene.add.rectangle(100, 100, 10, 10, 0xff0000)
const rectangleWithPhysics = scene.physics.add.existing(rectangle)
// cannot do rectangleWithPhysics.setBounce !
All I want is to create a geometric object that has all the methods as when I created a rectangle from an image like below:
scene.physics.add.image(300, 300, 'rectangleImage') // gives me all the methods I want, like setBounce !
scene.physics.add.existing
will only give the Game Object passed to it a physics body. add.image
and add.sprite
, on the other hand, create special subclasses of the respective Game Object which pull in those methods. For any other Game Object, you can find equivalent methods on its body
property.
The physics-related methods on Arcade Images and Arcade Sprites come from the mixins in the Phaser.Physics.Arcade.Components
namespace. If you really want them on your shape Game Objects, you can make your own child classes and apply those mixins to them - or just apply them directly to the constructed objects. If I were you, however, I would just use the body
property.
1 Like