Jump to content

Timer problem - calling external objects method [SOLVED]


pinkpanther
 Share

Recommended Posts

Hello,

 

what's wrong with this code:

 

this.player = new Player(game.system.width / 2, game.system.height - this.ground.height);
              this.enemyRow = new EnemyGroup();
              console.log(this.player);
              console.log(this.enemyRow);
              
              this.addTimer(5000, function() {
                  this.enemyRow.fallDown();
              }, true);

 

 

That gives me TypeError (this.enemyRow.fallDown: undefined)

 

Regards!

 

Link to comment
Share on other sites

Ok, i passed timer issue, but still got the problem with references on line

 

                  e = this.enemies[r];

 

in fallDown method.

Still TypeError: undefined. I Suppose, this is due to binding in scene:

 

 this.addTimer(5000, this.enemyRow.fallDown.bind(this), true);

 

where enemyRow is EnemyGroup class object.

 

Important code goes here:

 

 EnemyGroup = game.Class.extend({
          // enemies : [null, null, null, null, null, null, null],
          
          acceleration : 0,
          speed : 7,
          number : enemyRows * enemyCols,
          
          init : function() {
              
              var r, i;
              this.enemies = new Array();
              // Choose start direction
              if (Math.random() > 0.5) {
                  this.acceleration = 1;
              }
              else {
                  this.acceleration = -1;
              }
              // init row of enemies
              for (r = 0; r <= enemyCols - 1; r++) {
                  this.enemies.push(new Enemy(parseInt(game.system.width / 7 + r * game.system.width * 0.15),
                      parseInt(game.system.height * 0.05), this));
                  // this.enemies[r].acceleration = this.acceleration;
                  this.enemies[r].body.velocity.x *= this.acceleration;
              }
              
              console.log(this.enemies);
              // init falling
              
              game.scene.addObject(this);
          },

 

fallDown : function() {
              var r, i;
              console.log(this.enemies);
              
              for (r = 0; r <= enemyCols - 1; r++) {
                  e = this.enemies[r];
                  if (e == null) continue;
                  if (this.enemies[r] != null) {
                      var e = this.enemies[r];
                      e.startfall();
                  }
                  
              };
          },

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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