So, I've only had the chance to test this out today, (working on a ton of different projects in parallel for college sucks), and it works, but now I'm running into a different error:
My function is taking a bunch of arguments to augment the group, creating multiple sprites, enabling physics, etc.
createSpriteGroup: function(groupName, physics, number, key, reward, dropRate, animated, delay) {
this[groupName] = this.add.group();
this[groupName].createMultiple(number, key);
if(physics){
this[groupName].enableBody=true;
this[groupName].physicsBodyType=Phaser.Physics.ARCADE;
this[groupName].setAll('outOfBoundsKill', true);
this[groupName].setAll('checkWorldBounds', true);
}
this[groupName].setAll('anchor.x', 0.5);
this[groupName].setAll('anchor.y', 0.5);
this[groupName].setAll('reward', reward, false, false, 0, true);
this[groupName].setAll('dropRate', dropRate, false, false, 0, true);
if(animated){
this[groupName].forEach(function(unit){
unit.animations.add('fly', [0,1,2,0], 20, true);
unit.animations.add('hit', [3,1,3,2,3], 20, false);
unit.events.onAnimationComplete.add(function(u){
u.play('fly');
}, this);
});
}
if(delay>0){
this[groupName].resTime = delay;
}
},
I'm calling it like this:
this.createSpriteGroup('enemyPool', true, 200, 'greenEnemy', BasicGame.ENEMY_REWARD, BasicGame.ENEMY_DROP_RATE, true, BasicGame.SPAWN_ENEMY_DELAY);
this.nextEnemyAt = 0; //also calling this,
But when the game tries to access the sprites through:
spawnEnemies: function() {
if (this.nextEnemyAt < this.time.now && this.enemyPool.countDead() > 0) {
this.nextEnemyAt = this.time.now + this.enemyPool.resTime;
var enemy = this.enemyPool.getFirstExists(false);
enemy.reset(this.rnd.integerInRange(20, this.game.width - 20), 0, BasicGame.ENEMY_HEALTH); //this line here
enemy.body.velocity.y = this.rnd.integerInRange(BasicGame.ENEMY_MIN_Y_VELOCITY, BasicGame.ENEMY_MAX_Y_VELOCITY);
enemy.play('fly');
}
It's returning "Uncaught TypeError: Cannot read property 'velocity' of null" in the commented line.
Sorry for the ton of pasted code,
Any insights?