# igkman

Members

13

• Rank
Member

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

2. ## How to call a custom function of a child in a group

That's what it's suppose to do. I might be misinterpreting the function though
3. ## How to call a custom function of a child in a group

enemies.getAt(this.cnt) is supposed to return a child of the group "enemies" at the index 'this.cnt'. cnt is an integer set at zero. does that help?
4. ## How to call a custom function of a child in a group

How is that? The problem lies within the update function of the Game class.
5. ## How to call a custom function of a child in a group

Game = function(game) { this.timer = 0; this.cycle = 1000; this.cnt = 0; } Phaser.GameObjectFactory.prototype.enemy = function(x,y,xPix,yPix,enemyNum) { return this.game.add.existing(new Enemy(this.game,x,y,xPix,yPix,enemyNum) ); } Game.prototype = { create: function() { game.physics.startSystem(Phaser.Physics.ARCADE); enemies = game.add.group(); enemies.enableBody = true; // locations for the first group of enemies to fly in var group1PixelLocations = { 'x' : [game.width/2,game.width/2-30,game.width/2,game.width/2-30, game.width/2,game.width/2-30,game.width/2,game.width/2-30], 'y' : [(game.height/2)-30,(game.height/2)-30,(game.height/2)-60,(game.height/2)-60, (game.height/2)-90,(game.height/2)-90,(game.height/2)-120,(game.height/2)-120], }; //create enemies for (var i = 0; i < 8; i = i+2) { enemies.create(game.add.enemy(game.width/1.33,0,group1PixelLocations.x[i],group1PixelLocations.y[i],0)); //create another enemy object with opposite coordinates enemies.create(game.add.enemy(game.width/4,0,group1PixelLocations.x[i+1],group1PixelLocations.y[i+1],1)); } }, update: function() { if (game.time.now > this.timer) { this.timer = game.time.now + this.cycle; var en = enemies.getAt(this.cnt); // this is the function I want each child to perform en.group1Path(); this.cnt = this.cnt + 1; } } }; I'm trying to call a function that I created in the Enemy class(below) with the children in my group. However, the error I get is 'Uncaught TypeError: en.group1Path is not a function' . Which is odd becuase the group consists of Enemy objects. Enemy class: var Enemy = function(game,x,y,xPix,yPix,enemyNum) { Phaser.Sprite.call(this,game,x,y,''); this.xPix = xPix; this.yPix = yPix; this.enemyNum = enemyNum; this.create(); } Enemy.prototype = Object.create(Phaser.Sprite.prototype); Enemy.prototype.constructor = Enemy; var completed = false; Enemy.prototype.preload = function() { } Enemy.prototype.create = function() { //this.group1Path(); } Enemy.prototype.update = function() { if (!this.exists) return; if (completed) game.physics.arcade.moveToObject(this.enemy,this.pixel,100); } Enemy.prototype.isComplete = function() { completed = true; } //path of the first group Enemy.prototype.group1Path = function() { /*This is the function to be called*/ }

7. ## How can I add multiple instances of a class to a group?

This worked! Thank you so much!