Jump to content

collideWorldBounds=false disables ALL collisions ?!


valueerror
 Share

Recommended Posts

oke.. obviously there is more information needed...   

i'm trying to create a very simple game with some kids and i'm really confused

 

the current problem is that setting 

sprite.body.collideWorldBounds = true;

  for any object disables ALL collisions for this object..   i just don't see why..  (i've never used this setting before so i have no experience on how to use it properly.. maybe i made a simple coding error..

 

thx for your help! 

here's the code:   (the flower doesn't collide with the other objects because of the worldbounds setting)

function create() {    game.physics.startSystem(Phaser.Physics.P2JS);    game.physics.p2.gravity.y = 1000;    cursors = game.input.keyboard.createCursorKeys();    game.add.tileSprite(0,0,800, 600, 'clouds');    ball1 = game.add.sprite(200,140,'ball');    game.physics.p2.enable( ball1 );    ball1.body.setCircle(32);    ball1.body.damping = 0.9;    flower1 = game.add.sprite(402,50,'flower');    game.physics.p2.enable( flower1 );    flower1.body.setCircle(32);    flower1.body.damping = 0.9;    flower1.body.collideWorldBounds = false;    schmetti = game.add.sprite(400,200,'schmetti');    game.physics.p2.enable(schmetti);    schmetti.body.setCircle(25);    bowlingballs = game.add.group();    bowlingballs.add(ball1);    bowlingballs.add(flower1);}function update() {    if (cursors.right.isDown){schmetti.body.moveRight(300);}    if (cursors.left.isDown) {schmetti.body.moveLeft(300); }    if (cursors.up.isDown)   {schmetti.body.moveUp(300);   }    bowlingballs.forEach(position);}var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', {preload:preload, create:create, update:update});function position(mitglied){    if (mitglied.body.y >= 550){        mitglied.body.y = 40;    }}
Link to comment
Share on other sites

  • 3 weeks later...

The property name "collideWorldBounds" is misleading.

What happens is that when you create physics bodies in P2 they all get assigned and put into a default collision group, that includes the world boundaries.

When you set "collideWorldBounds" to false you remove it from that group and so it collides with nothing else that is also in the default group. You will have to set up collision groups to get the desired effect you want.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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