Jump to content

Tweening separate enemies defined in the same function


Recommended Posts

I have a function for my enemies (which in this game are bees)

Bees = function(index, game, x, y){
      this.bee = game.add.sprite(x,y,'bee');
      this.bee.name = index.toString();
      this.bee.body.allowGravity = 0;
      this.bee.body.immovable = true;
      this.bee.body.collideWorldBounds = true;

      this.beeTween = game.add.tween(this.bee).to({
        y: this.bee.y + 1

and to add them into the game I have 

Game.World1.prototype = {

        //other code.....

        enemy1 =  new Bees(0,game,240,40);
        enemy2 = new Bees(0,game,312,140);


However, once I place these enemies into the game, I have no idea how to make them move independently.

For example:

enemy1 =  new Bees(0,game,240,40);

this.enemy1Tween = game.add.tween(this.enemy1).to({
        x: this.enemy1.x - 40

Gives the error "Cannot read property 'x' of undefined" 

x: this.enemy1.x - 40

How can I make each enemy move independently?

Or even better, how can I go about making each enemy move along different length platforms without falling off?

Thank you.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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