Jump to content

Sprites not recycling


Joldror
 Share

Recommended Posts

Hi, I'm new (another one) with phaser. I did a test game without problems (or almost) but now I'm doing a game that throws objects ad infinitum. In order to do this  I'm sprite recycling. I have a group of sprites with outOfBoundsKill and checkWorldBounds set to true. And then when it's time to throw an object I fetch the first that does not exists. Here's my code:

// Coinsthis.coins = this.add.group();this.coins.enableBody = true;this.coins.physicsBodyType = Phaser.Physics.ARCADE;this.coins.createMultiple(4, 'coin');this.coins.setAll('outOfBoundKill', true);this.coins.setAll('checkWorldBounds', true);

And this is the function to throw coins (from the bottom of the world to the top):

throwSomething() {       this.coin = this.coins.getFirstExists(false);       this.coin.reset(this.throwers_x[droperNumber], this.throwers_y);       this.coin.animations.add('spin', [0, 1, 2, 3, 4, 5, 6, 7], 10, true);       this.coin.play('spin');       this.coin.body.gravity.y = -300;       this.dropingTimer = this.game.time.now + 2000;}

The moment all coins are created there's no coins with exists set to false. It should be, since outOfBoundKill is on. The animation add and play, and the body.gravity were in the create function at the beginning, but I changed to test things. Any ideas?

Link to comment
Share on other sites

I tried those events and the exists property was false always. Although I tried to debug with the Chrome developer tools using breakpoints, every iteraction one more coin was set to exists true, while none went back to false. My thought is either outOfBoundKill or checkWorldBounds is not triggering (or neither of them).

Link to comment
Share on other sites

Yes. I tested again just in case and the event onOutOfBounds is triggered every time.

 

EDIT: I tested again both events.

throwSomething() {            var throwerNumber = this.game.rnd.integerInRange(0, 2);            var throwedObject = this.game.rnd.integerInRange(1, 100);            if (throwedObject <= this.coinPercentage) {                this.coin = this.coins.getFirstExists(false);                this.coin.reset(this.throwers_x[throwerNumber], this.throwers_y);                this.coin.events.onOutOfBounds.addOnce(this.debugOut, this);                this.coin.events.onKilled.addOnce(this.debugKilled, this);                this.coin.animations.add('spin', [0, 1, 2, 3, 4, 5, 6, 7], 10, true);                this.coin.play('spin');                this.coin.body.gravity.y = -300;            }            else {                // TODO: throw dangers            }            this.throwingTimer = this.game.time.now + 2000;        }        debugOut() {            console.log('something is out of bounds');        }        debugKilled() {            console.log('something is dead');        }

And this is what I get in the java console:

out_of_bounds.png

Edited by Joldror
Link to comment
Share on other sites

But it does not change anything. The events are added for debug purpose only. The game should run ok with or without the events. Anyway, I tested with add instead of addOnce and teh result is exactly the same.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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