Jubawub Posted February 22, 2017 Share Posted February 22, 2017 I have a function for my enemies (which in this game are bees) Bees = function(index, game, x, y){ this.bee = game.add.sprite(x,y,'bee'); this.bee.anchor.setTo(0.5,0.5); this.bee.name = index.toString(); game.physics.enable(this.bee,Phaser.Physics.ARCADE); this.bee.body.allowGravity = 0; this.bee.body.immovable = true; this.bee.body.collideWorldBounds = true; this.beeTween = game.add.tween(this.bee).to({ y: this.bee.y + 1 },500,'Linear',true,0,-1,true); and to add them into the game I have Game.World1.prototype = { create:function(game){ //other code..... enemy1 = new Bees(0,game,240,40); enemy2 = new Bees(0,game,312,140); }, However, once I place these enemies into the game, I have no idea how to make them move independently. For example: enemy1 = new Bees(0,game,240,40); this.enemy1Tween = game.add.tween(this.enemy1).to({ x: this.enemy1.x - 40 },4000,'Linear',true,0,-1,true); Gives the error "Cannot read property 'x' of undefined" x: this.enemy1.x - 40 How can I make each enemy move independently? Or even better, how can I go about making each enemy move along different length platforms without falling off? Thank you. Link to comment Share on other sites More sharing options...
scheffgames Posted February 22, 2017 Share Posted February 22, 2017 The Bees function does not have an x property. The bee property inside the Bees function does have an x property. So write this instead: game.add.tween(this.enemy1.bee) Link to comment Share on other sites More sharing options...
Recommended Posts