CarlosBR Posted December 11, 2018 Share Posted December 11, 2018 this.enemies = this.physics.add.group(); this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' }); this.enemies.forEach((enemy) => { if(enemy instanceof Phaser.GameObjects.Sprite) { enemy.body.setBounceX(1); } }); With this code I get enemy.body is null or if I change to enemy.setBounceX(1) I get: enemy.setBounceX is not a function The code below: this.enemies = this.physics.add.group(); this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' }); this.enemies.getChildren().forEach(function(enemy) { enemy.body.setBounceX(1); }, this); also doesn't work. The error message says: this.enemies.getChildren is not a function What am I doing wrong here? Link to comment Share on other sites More sharing options...
rich Posted December 11, 2018 Share Posted December 11, 2018 Look at what `createFromObjects` returns, because it's overwriting your Physics Group. Link to comment Share on other sites More sharing options...
CarlosBR Posted December 11, 2018 Author Share Posted December 11, 2018 How do I create with createFromObjects and also make the objects belong to a group? I can't find a tutorial about it. Thanks for the reply. Link to comment Share on other sites More sharing options...
rich Posted December 11, 2018 Share Posted December 11, 2018 createFromObjects just returns an array. Place the contents of it into a Group. Link to comment Share on other sites More sharing options...
CarlosBR Posted December 11, 2018 Author Share Posted December 11, 2018 Thanks for the help. Link to comment Share on other sites More sharing options...
Recommended Posts