Joldror Posted April 2, 2014 Share Posted April 2, 2014 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 More sharing options...
rich Posted April 2, 2014 Share Posted April 2, 2014 Hard to say without seeing more code, but Sprites have 4 events you could listen to that will help debug this problem for you:Sprite.events.onKilledSprite.events.onRevivedSprite.events.onOutOfBoundsSprite.events.onEnterBounds Link to comment Share on other sites More sharing options...
Joldror Posted April 2, 2014 Author Share Posted April 2, 2014 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 More sharing options...
rich Posted April 2, 2014 Share Posted April 2, 2014 Do you ever get the onOutOfBounds event though? If not, then the object doesn't think it has left the world. Link to comment Share on other sites More sharing options...
Joldror Posted April 2, 2014 Author Share Posted April 2, 2014 (edited) 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: Edited April 2, 2014 by Joldror Link to comment Share on other sites More sharing options...
rich Posted April 2, 2014 Share Posted April 2, 2014 You're using addOnce for the events, which means that callback can only be called once - ever, even if the coin is recycled and re-used later. You probably want to use add instead. Link to comment Share on other sites More sharing options...
Joldror Posted April 2, 2014 Author Share Posted April 2, 2014 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 More sharing options...
Joldror Posted April 3, 2014 Author Share Posted April 3, 2014 I feel more than stupid. It's outOfBoundsKill and not outOfBoundKill like I wrote it. Link to comment Share on other sites More sharing options...
rich Posted April 3, 2014 Share Posted April 3, 2014 Don't feel stupid for solving something LeonardoDigital and ClonkMobile 2 Link to comment Share on other sites More sharing options...
Recommended Posts