mattbrand Posted May 12, 2021 Share Posted May 12, 2021 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.setCollideWorldBounds(true); this.setVelocity(100, 100); this.setBounce(1); 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); bubble.setCollideWorldBounds(true); bubble.setBounce(1); this.bubbleGroup.add(bubble); 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 More sharing options...
Horizonicblue Posted May 13, 2021 Share Posted May 13, 2021 Haven't tried this way but I feel you are missing scene.add.existing(this); scene.physics.add.existing(this); https://phaser.io/examples/v3/view/physics/arcade/extending-arcade-sprite mattbrand 1 Link to comment Share on other sites More sharing options...
mattbrand Posted May 13, 2021 Author Share Posted May 13, 2021 (edited) Ah ok. I was adding it to the scene, but was not adding it to the physics. Thank you! Edited May 13, 2021 by mattbrand Link to comment Share on other sites More sharing options...
Recommended Posts