xronn Posted October 11, 2015 Share Posted October 11, 2015 Hi, I'm starting to build up a huge number of sprites so I was wondering instead of setting the same body value for each sprite as shown below; beachnpc = this.add.sprite(810, 6472, 'beachnpc');beachnpc.body.setSize(70, 70, 0, 0);beachnpc.body.immovable = true;beachnpc.body.moves = false;forestnpc= this.add.sprite(1110, 3472, 'forestnpc');forestnpc.body.setSize(70, 70, 0, 0);forestnpc.body.immovable = true;forestnpc.body.moves = false;warriornpc= this.add.sprite(3110, 1860, 'warriornpc');warriornpc.body.setSize(70, 70, 0, 0);warriornpc.body.immovable = true;warriornpc.body.moves = false;So I was trying to put that repeat code into a group as shown:questnpc = this.add.group();this.physics.enable(questnpc, Phaser.Physics.ARCADE);questnpc.body.setSize(70, 70, 0, 0);questnpc.body.immovable = true;questnpc.body.moves = false;But I get undefined 'setSize' is it possible to do something like this? Or do I have to repeat all of my code for each sprite? Link to comment Share on other sites More sharing options...
bruno_ Posted October 11, 2015 Share Posted October 11, 2015 You can do a foreach of the group elements Link to comment Share on other sites More sharing options...
shohan4556 Posted October 12, 2015 Share Posted October 12, 2015 questnpcGroup = game.add.physicsGroup(Phaser.Physics.ARCADE);questnpcGroup.createMultiple(10,'mysprite',null,false);questnpcGroup.setAll('body.setSize','body',70,70,0,0);I usally follow this way. after doing this you cant debug questnpcGroup body because group has not any body. Link to comment Share on other sites More sharing options...
Recommended Posts