i3Designer Posted September 7, 2014 Share Posted September 7, 2014 I created a group of enemy and I want that this group follows an object.I created a group in function create: this.gruppo = game.add.group(); for ( var i = 0; i <= 10; i++ ) { this.sprite = this.gruppo.create(game.world.randomX,game.world.randomY,'Paolo'); game.physics.enable(this.sprite,Phaser.Physics.ARCADE); } this.gruppo.setAll('body.collideWorldBounds',true); I use this for only sprite game.physics.arcade.moveToObject(this.sprite, {x: this.oggetto.x, y:this.oggetto.y}, 100, this); but I want to do that all the sprites in the group follow an object.I tried several solutions, but I can not. Link to comment Share on other sites More sharing options...
danbruegge Posted September 7, 2014 Share Posted September 7, 2014 You can use this for groups, too.game.physics.arcade.moveToObject(this.gruppo, {x: this.oggetto.x, y:this.oggetto.y}, 100, this); Link to comment Share on other sites More sharing options...
i3Designer Posted September 7, 2014 Author Share Posted September 7, 2014 I've tried. Link to comment Share on other sites More sharing options...
danbruegge Posted September 7, 2014 Share Posted September 7, 2014 Oh my fault, sorry. I thought it will work but the docs says no. http://docs.phaser.io/Phaser.Physics.Arcade.html#moveToObject But you can iterate over the group. http://docs.phaser.io/Phaser.Group.html#forEachthis.gruppo.forEach(function (sprite) { ...moveToObject(sprite, ...);}, this); TerryScrimsher 1 Link to comment Share on other sites More sharing options...
i3Designer Posted September 7, 2014 Author Share Posted September 7, 2014 I tried forEach but something was wrong. Thank you very much! danbruegge 1 Link to comment Share on other sites More sharing options...
TerryScrimsher Posted May 21, 2016 Share Posted May 21, 2016 Worked perfectly for my problem: foxes.forEach(function (fox) {game.physics.arcade.moveToObject(fox, s, 50)}); Link to comment Share on other sites More sharing options...
Recommended Posts