Jump to content



Recommended Posts

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

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 timer
enemiesCtrl: function(){
//need to edit this to do something different down the track
   if(this.enemyTimer >= 50 && this.enemyCounter <= 15){
       this.enemyTimer = 0;
       this.enemyCounter ++;
       this.enemyTimer ++;
//creates new enemy within enemies group
enemySpawner: 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);
//repositions the enemy and resets direction
enemyReset: function(enemy){
var side = Math.floor((Math.random()*2)+1);
        enemy.x = -30;
        enemy.y = Math.floor((Math.random() * 800) + 1);
        enemy.body.velocity.x = 100;
        enemy.x = 800;
        enemy.y = Math.floor((Math.random() * 800) + 1);
        enemy.body.velocity.x = -100;
//triggers reset function when enemy leaves the screen
enemyOob: function(enemy){
if((enemy.y >750 && enemy.body.velocity > 0)||(enemy.y <50 && enemy.body.velocity < 0)){
Link to comment
Share on other sites


  • Recently Browsing   0 members

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