I am making a game where a chicken is dropping eggs from the sky. However I am having trouble getting the eggs to ‘fall’. I added it as a group with physics enabled. But I cant seem to get the ‘body’ property to come back as anything as null. Here is the relevant code:
class Egg extends Phaser.GameObjects.Sprite {
constructor(scene) {
var x = scene.chicken.x;
var y = scene.chicken.y + 80;
super(scene, x, y, "egg");
// Add the egg to the scene
scene.add.existing(this);
this.play("egg_anim");
// enable physics
scene.physics.world.enableBody(this);
this.body.velocity.y = -250;
// Add the beam to the projectiles group in scene 2
scene.projectiles.add(this);
}
}
And this is how I add it to the projectiles group:
this.projectiles = this.physics.add.group();
thanks so much!