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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.