igkman Posted November 22, 2016 Share Posted November 22, 2016 var group1PixelLocations = { 'x' : [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)-60,(game.height/2)-90,(game.height/2)-120,(game.height/2)-150], }; //create enemies for (var i = 0; i < 5; i++) { enemies.create(game.add.enemy(game.width/1.33,0,group1PixelLocations.x[i],group1PixelLocations.y[i])); } The last two parameters of game.add.enemy() ,xPix and yPix, are undefined when I try to pass them unto my Enemy Class: var Enemy = function(game,x,y,xPix,yPix) { Phaser.Sprite.call(this,game,x,y,''); // for some reason, xPix and yPix are undefined alert(xPix + ' ' + yPix); this.create(); } Enemy.prototype = Object.create(Phaser.Sprite.prototype); Enemy.prototype.constructor = Enemy; var completed = false; Enemy.prototype.preload = function() { } Enemy.prototype.create = function() { var enemySprites = ['enemy1','enemy2','enemy3']; // enemy sprite and its animation this.enemy = game.add.sprite(this.x,this.y,enemySprites[0]); this.enemy.anchor.set = 0.5; this.enemy.animations.add(enemySprites[0],null,10,true); this.enemy.animations.play(enemySprites[0]); //This will be tracked by the enemy sprite //will be set to invisible this.pixel = game.add.sprite(this.xPix,this.yPix,'pixel'); //this.pixel.visible = false; /*alert(this.xPix+ ' ' + this.yPix);*/ game.physics.arcade.enable(this.enemy); game.physics.arcade.enable(this.pixel); this.sideTween(); this.group1Path(); } Enemy.prototype.update = function() { if (!this.exists) return; if (completed) game.physics.arcade.moveToObject(this.enemy,this.pixel,100); } /*the path of pixel moves back and forth represents the movement of enemy sprites while enemies are flying in*/ Enemy.prototype.sideTween = function() { this.tween = game.add.tween(this.pixel).to({x: this.xPix + 400}, 2000, null,-1,true); this.tween.yoyo(true,0,0); this.tween.repeat(-1); this.tween.start(); } Link to comment Share on other sites More sharing options...
Recommended Posts