Jump to content

Cannot use physics on a class that extends Phaser.Physics.Arcade.Sprite


Recommended Posts

Hey all!

I have a class that looks like this:

export default class Bubble extends Phaser.Physics.Arcade.Sprite
    private text:Phaser.GameObjects.Text;
    private velocity:Phaser.Math.Vector2;
    private dragging:Boolean;
    private game:Game;

    constructor(scene, game, x, y)

I want to set up physics on these objects (the bubbles). I've tried 2 ways to do this.

1. Set up the physics directly in the class constructor itself:

this.setVelocity(100, 100);

2. Set up in my game's main scene where I instantiate the bubbles:

let bubble = new Bubble(this, this.game, x, y);
bubble.setVelocity(100, 100);
this.physics.overlap(bubble, this.bubbleGroup, this.bubbleHitBubble);

Neither of these work. I get "TypeError: Cannot read property 'setVelocity' of null".

Why can I not set physics properties on the bubbles if they extend Phaser.Physics.Arcade.Sprite?

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...