Jump to content

Run a function when items move offscreen


Recommended Posts

I'm new to game development and I haven't been able to get any of the solutions from previous topics on this problem to work.

I want the squares moving across the bottom of the screen to 'die' and run a function to increment a wastedItem number when they leave the screen.

I have tried several methods to get this to work:

1. element.onOutOfBounds.add(this.killItem, this); //I can get the function to run,

but it seems to run about 50-100 times even if I kill the object first and then run the function

2. I tried to add rectangles as tall as the screen to and use an overlap function: this.game.physics.arcade.overlap(element, this.wallRight, this.killItem, null, this);

This function does not even run no matter where I seem to put it in the code.

I would like to get option #1 to work and run the killItem function only once. I am probably doing something wrong because of a lack of understanding of Phaser.

I would seriously appreciate any help with this.

Here is my code: https://github.com/gwenf/phaser-object-throw (only one relevant main.js file, the code needs to be cleaned up a lot I know, but I am just trying to get this to work.)

and here is a live demo: https://gwenf.github.io/phaser-object-throw/

Link to comment
Share on other sites


  • Recently Browsing   0 members

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