Jump to content

Collide Only With Left Or Right Bounds


oliversb
 Share

Recommended Posts

How do I get the body to only collide with left or right bounds? I am using arcade physics and tried to convert this over with from a post using a different physics system.

'function createPreviewBounds(x, y, w, h) {
    var sim = game.physics.arcade;
    
    customBounds.left = new Phaser.Body({ mass: 0, position: [ x, y ], angle: 1.5707963267948966 });
    customBounds.left.addShape(new Plane());
    
    customBounds.right = new Phaser.Body({ mass: 0, position: [ x + w, y ], angle: -1.5707963267948966 });
    customBounds.right.addShape(new Phaser.Plane());
    // customBounds.right.shapes[0].collisionGroup = mask;

    customBounds.top = new Phaser.Body({ mass: 0, position: [ x, y ], angle: -3.141592653589793 });
    customBounds.top.addShape(new Phaser.Plane());
    // customBounds.top.shapes[0].collisionGroup = mask;

    customBounds.bottom = new Phaser.Body({ mass: 0, position: [ x, y + h ] });
    customBounds.bottom.addShape(new Phaser.Plane());
    // customBounds.bottom.shapes[0].collisionGroup = mask;
    
    sim.world.addBody(customBounds.left);
    sim.world.addBody(customBounds.right);
    sim.world.addBody(customBounds.top);
    sim.world.addBody(customBounds.bottom);
}'
 

I wrote this code were I wanted to createPreviewBounds

'//create bounds
    var bounds = new Phaser.Rectangle(100, 100, 400, 400);
    customBounds = { left: null, right: null, top: null, bottom: null };
    
    createPreviewBounds(bounds.x, bounds.y, bounds.width, bounds.height);'

I cannot seem to find the right constructor.

Thanks

 

 

Link to comment
Share on other sites

Arcade Physics bodies collide only with the World bounds and with other bodies. So I think your options are

  1. Use collideWorldBounds=true
  2. Use 4 blank, physics-enabled sprites to form a rectangle
  3. Create a Phaser.Rectangle and write your own collision method
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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