Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

how to add listener or callback to onOutOfBounds event


misfit
 Share

Recommended Posts

So i want to add listener to when the sprite goes out of bounds of the screen. It doesn't seem to fire up. Am I missing something? I saw a post here about this but it uses this.physics.world.on("worldbounds".. but isn't there a way to encapsulate the listener inside a new Sprite child class? Btw is there a list of events i can listen to? Thanks!

class Meteor extends Phaser.Physics.Arcade.Sprite{
   constructor(scene,x,y,key_texture,frame){
      super(scene,x,y,key_texture,frame);
      this.scene = scene;
      this.scene.addToWorld(this);
      this.scene.physics.add.existing(this,false);
      this.setCollideWorldBounds(true);
      this.addListener("onOutOfBounds",()=>{console.log("hello")});
   }
}

 

Ok so apparently if i am setting this.collideWorldBounds(true) it console.logs this.body.onWOrlBounds as true but console.log this has it set to false. If I add a new Meteor(..) from scene.create() method it works fine. If I add it from Spawner class it doesn't.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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