Jump to content

Set body of all group sprites?


Recommended Posts



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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...