Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Boss Movement Method


Code4Breakfast
 Share

Recommended Posts

I am working on a boss movement method. The idea is that every 8 seconds the method will be called from the create method, this may be part of the problem... The idea is that every 8 seconds the method will be called. The boss will appear from one side of the screen and exit to the other. The bosses y coord will be based on where players y coord.  The issue I am running into is that when the level starts the boss starts moving before 8 seconds goes across the screen to exit and is never seen again. I am not moving the player during the test so the bird isn't going beyond the y screen parameters. The console is only logging the side once so it only seem to be getting called once. 

My relevant code below:

// inside the create method

this.blueBirds = this.add.group();
this.blueBirds.enableBody = true;

 

this.multiBlueBirdFlight = this.game.time.events.loop(Phaser.Time.SECOND * 8, this.flyBlueBird(), this);

 

// inside the game state

flyBlueBird: function () {
    
    var blueBird = this.blueBirds.getFirstExists();

    if (!blueBird) {
      blueBird = this.blueBirds.create(this.X_MIN, this.player.y -100, 'blueBird');
      blueBird.anchor.setTo(0.5);
      blueBird.customParams = {};
      blueBird.customParams.side = 'left'
      blueBird.body.allowGravity = false;
      blueBird.animations.add('flying', [0,1,2,3], 5, true);
    }

    if (blueBird.customParams.side == 'left') {
      blueBird.reset(this.X_MIN , this.player.y - 100)
        blueBird.body.velocity.x = 100;
        blueBird.body.velocity.y = -10;
        blueBird.customParams.side = 'right';
    } else {
         blueBird.reset(this.X_MAX + 50, this.player.y - 100);
      
         blueBird.body.velocity.x = -100;
         blueBird.body.velocity.y = -10;

        blueBird.customParams.side = 'left';
     }
       
      
         blueBird.play('flying')
         console.log(blueBird.customParam.side)
  }

Link to comment
Share on other sites

The problem is in this line:

this.multiBlueBirdFlight = this.game.time.events.loop(Phaser.Time.SECOND * 8, this.flyBlueBird(), this);

You're not saying "here is the name of the function I want you to call", you're saying "run this function right now and pass its result to the timer". You probably meant "this.game.time.events.loop(Phaser.Time.SECOND * 8, this.flyBlueBird, this);" Notice how there aren't parenthesis after this.flyBlueBird? That means you're passing the name of the function, not the result of the function. Does that make sense?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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