Matt Posted October 13, 2014 Share Posted October 13, 2014 Hi everyone, I'm new to phaser and to this forum google couldn't find me an answer so i had to make an account to post. I am having an issue with onOutOfBounds being triggered when a sprite is entering.This happens at random and tends to happen several times to the one sprite in a row just wondering what could cause this and how exactly does onOutOfBounds work? Link to comment Share on other sites More sharing options...
totallybueno Posted October 13, 2014 Share Posted October 13, 2014 Hi Matt, onOutOfBounds is dispatched when a sprite leaves the world, that´s all.Also, you can kill that sprite if its property outOfBoundsKill is true. Hope it helps. Link to comment Share on other sites More sharing options...
Matt Posted October 13, 2014 Author Share Posted October 13, 2014 Hey, thanks for the reply,I did already understand that much about the event,still not sure why the event is being triggered several times in one frame. here is the code that i'm using;I may have altered it a little by now but any feedback will help //spawns enemies on a timerenemiesCtrl: function(){//need to edit this to do something different down the track if(this.enemyTimer >= 50 && this.enemyCounter <= 15){ this.enemyTimer = 0; this.enemySpawner(); this.enemyCounter ++; }else{ this.enemyTimer ++; }},//creates new enemy within enemies groupenemySpawner: function(){ var enemy = this.enemies.create(-30, -30, 'red'); enemy.scale.setTo(0.5, 0.5); enemy.checkWorldBounds = true;enemy.events.onOutOfBounds.add(this.enemyOob, this); this.enemyReset(enemy); },//repositions the enemy and resets directionenemyReset: function(enemy){var side = Math.floor((Math.random()*2)+1); if(side==1){ enemy.x = -30; enemy.y = Math.floor((Math.random() * 800) + 1); enemy.body.velocity.x = 100; }else{ enemy.x = 800; enemy.y = Math.floor((Math.random() * 800) + 1); enemy.body.velocity.x = -100; }},//triggers reset function when enemy leaves the screenenemyOob: function(enemy){if((enemy.y >750 && enemy.body.velocity > 0)||(enemy.y <50 && enemy.body.velocity < 0)){this.enemyReset(enemy);;}} Link to comment Share on other sites More sharing options...
totallybueno Posted October 13, 2014 Share Posted October 13, 2014 Well, I guess more than one enemy are leaving the world in that frame/step... Link to comment Share on other sites More sharing options...
Matt Posted October 13, 2014 Author Share Posted October 13, 2014 oh okay, i can work with that Link to comment Share on other sites More sharing options...
totallybueno Posted October 13, 2014 Share Posted October 13, 2014 Link to comment Share on other sites More sharing options...
Recommended Posts