Search the Community
Showing results for tags 'onOutOfBounds'.
-
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.
-
Hi, I was wondering which one would be. I have set the game's viewport to 800x600 and the world bounds to 2048x1024. The player moves and the camera follows it. I want to dynamically load the tiles that are in the bounds of the viewport while the player moves around and kill the ones that are out. I was naively trying to kill() onOutOfBounds and then revive() onEnterBounds. Did not work but i don't know why. Apparently behind scenes is doing: !this.game.world.bounds.intersects(this._bounds)So i tried to replicate the functionality building an array of the killed tiles onOutOfBounds and, on the update() method, iterate over the killed tiles to check the intersect: if( game.world.bounds.intersects(killedTiles[i]._bounds) ){ killedTiles[i].revive();}The conditional is always false (?) and the ammount of process seems like an overkill for me (for big maps). Anyway i am using isometric phaser plugin if that makes any difference (i tried also with killedTiles._isoBounds). Someone has any tips?
- 1 reply
-
- isometric
- intersects
-
(and 2 more)
Tagged with: