Jump to content

World bounds in P2JS


yegorf1
 Share

Recommended Posts

Here again. My circles are ignoring world bounds.

So there is code:

this.game.world.setBounds(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);this.game.physics.startSystem(Phaser.Physics.P2JS);this.game.physics.p2.restitution = 0.8;this.game.physics.p2.updateBoundsCollisionGroup();//...////...////...//chipsCollisionGroup = this.game.physics.p2.createCollisionGroup();this.chips = this.game.add.group();this.chips.enableBody = true;this.chips.physicsBodyType = Phaser.Physics.P2JS;//...////...////...//function setupChip(chip, owner, game) {	if (chipsCount[owner] < 1)		return false;	var MAX_MASS = 6;	var mass = Math.ceil(Math.random() * (MAX_MASS - 1)) + 1;	chip.scale.setTo(convertY(CHIP_SIZE / MAX_MASS * mass) / 64);	chip.mass = mass * 100;	chip.anchor.setTo(0.5, 0.5);	chip.tint = PLAYERS_COLORS[owner];	chip.owner = owner;	chip.dragging = false;	chip.body.setCollisionGroup(chipsCollisionGroup);	chip.body.collides(chipsCollisionGroup);	chip.body.setCircle(chip.width / 2);	chip.inputEnabled = true;	chip.input.start(0, true);	chip.events.onInputDown.add(drag);	chip.events.onInputUp.add(stopDrag);	return true;}//Usally previous function calls like thisvar chip = state.chips.create(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 'chip');setupChip(chip, PLAYER_FIRST, state.game);
Link to comment
Share on other sites

are your circles colliding with anything?   or are they properly colliding with other objects except the worldbounds?

 

if collision is not working at all - i'd try setting the circle BEFORE setting the collision group and the collides() statement...   setting a circle resets almost everything concerning the physics body so it is very likely that it resets your collision settings...  

 

add sprite

scale sprite

set circle

set collision settings 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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