Jump to content

P2 collision world or delete out of screen


Recommended Posts

What I'm trying to do is have 2 objects: one stuck on screen, and one moving with P2 physics.

But from all my testing, what I've gotten down to is that I have 2 choices:
1. No collision between the objects, but able to detect when it goes out of screen
2. Objects collide but can't detect when goes out of screen

So my question is... How do I combine that?
This is my code now:

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', {
	preload: preload,
	create: create

function preload() {
	game.load.image('block', 'assets/block.png');

function create() {
	game.stage.disableVisibilityChange = true; //keep running on lost focus
	game.world.setBounds(0, 0, 800, 600);
	game.physics.p2.gravity.y = 250;

	//create objects
	var stuck = game.add.sprite(400, 350, 'block');
	var stucknon = game.add.sprite(480, 150, 'block');

	game.physics.p2.enable([stuck, stucknon]);

	stuck.body.static = true;

If I have the code for collision groups and collisions, then it will just fall through each other and not collide at all.

The reason I'm using P2 is because I want the realistic/rotating gravity effect

So what do I need to add to make the moving object ("stucknon") fall through the screen and then delete it?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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