pinkpanther Posted July 10, 2014 Share Posted July 10, 2014 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! Quote Link to comment Share on other sites More sharing options...
powerman23rus Posted July 10, 2014 Share Posted July 10, 2014 Hey. Can you give me the source code of the object EnemyGroup? Quote Link to comment Share on other sites More sharing options...
pinkpanther Posted July 10, 2014 Author Share Posted July 10, 2014 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(); } }; }, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.