Sign in to follow this  
Johanna12221

P2 collision world or delete out of screen

Recommended Posts

Hi!
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
or
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.startSystem(Phaser.Physics.P2JS);
	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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.