Jump to content

group.body


SIXII
 Share

Recommended Posts

Hi, guys. I'll trying out Phaser and that's the issue which i got.

I'm creating a group

borders = game.add.group();

Next i filled group

        var rect1 = borders.create(game.rnd.integerInRange(0, 50), game.rnd.integerInRange(0, 80), 'rect1');
        var recthor = borders.create(game.rnd.integerInRange(5, 65), game.rnd.integerInRange(175, 270), 'recthor');
        var rectver = borders.create(game.rnd.integerInRange(320, 415), game.rnd.integerInRange(10, 65), 'rectver');
        var square = borders.create(game.rnd.integerInRange(270, 380), game.rnd.integerInRange(190, 255), 'square');

Then i have to set collideWorldBounds to true for each item of this group

        rect1.body.collideWorldBounds = true;
        recver.body.collideWorldBounds = true;
        recthor.body.collideWorldBounds = true;
        square.body.collideWorldBounds = true;

Is there way to set group params at once? Something like:

borders.body.collideWordBounds = true;

 

Link to comment
Share on other sites

1 hour ago, rich said:

Groups are like buckets of objects, they don't have any visual (or physics) properties of their own. However they do have lots of iteration methods, so you can do:


group.setAll('body.collideWorldBounds', true);

 

Thanks

Link to comment
Share on other sites

4 hours ago, rich said:

Can u pls explain, why


group.setAll('body.bounce', 1);

is not working?
In other case i used the constuction below and is working perfectly. what i'm doing wrong?


sprite.body.bounce.set(1);

Also if i want to use the several params, can i use smthing like that?


group.setAll('body.velocity',[100,100]);

 

 

Link to comment
Share on other sites

Because 'bounce' is a Point object, so what you're trying to do with setAll there is change a Point object to 1. What you actually want to do is either to call the 'set' function, or set the x and y values. So one of the following would work:

group.setAll('body.bounce.x', 1);
group.setAll('body.bounce.y', 1);

// ... or

group.callAll('body.bounce.set', 'body.bounce', 1);

 

Link to comment
Share on other sites

12 hours ago, rich said:

Because 'bounce' is a Point object, so what you're trying to do with setAll there is change a Point object to 1. What you actually want to do is either to call the 'set' function, or set the x and y values. So one of the following would work:


group.setAll('body.bounce.x', 1);
group.setAll('body.bounce.y', 1);

// ... or

group.callAll('body.bounce.set', 'body.bounce', 1);

 

I love u. Thanks a lot.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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