Clickys Posted March 7, 2017 Share Posted March 7, 2017 Greetings , I load my images at preload function() , And in create function() i created an array of objects var Quote animalData = [ {key: 'chicken', text: 'CHICKEN'}, {key: 'horse', text: 'HORSE'}, {key: 'pig', text: 'PIG'}, {key: 'sheep', text: 'SHEEP'} ]; Quote this.animals = this.game.add.group() i created a group called animals and i want to iterate through my array animalData Quote animalData.forEach(function(element){ self.animals.create(200, this.game.world.centerY, element.key); }); Only one animal is appearing the pig . Does anyone have any idea why othe animals are not appear ? Link to comment Share on other sites More sharing options...
samme Posted March 7, 2017 Share Posted March 7, 2017 animalData.forEach(function(element) { console.log(this.game.world.centerY, element.key); self.animals.create(200, this.game.world.centerY, element.key); }); Link to comment Share on other sites More sharing options...
Clickys Posted March 7, 2017 Author Share Posted March 7, 2017 180 "chicken" main.js:28 180 "horse" main.js:28 180 "pig" main.js:28 180 "sheep" Should i add the images as sprites ? Because i only load the images Link to comment Share on other sites More sharing options...
Clickys Posted March 7, 2017 Author Share Posted March 7, 2017 ok i found out why, i added the code at the start of create() instead at the end . But why does it matter if is at the start or the end ? Link to comment Share on other sites More sharing options...
Recommended Posts