phaserjs / phaser-ce

Phaser CE is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
http://phaser.io
MIT License
1.34k stars 491 forks source link

P2 Body onBeginContact and onEndContact are messed up #639

Closed liv1n9 closed 5 years ago

liv1n9 commented 5 years ago

Version: Phaser 2 CE 13.2

I want to check if two object using P2 bodies are overlap or not. My solution: use a boolean variable overlap = false, when onBeginContact, set overlap = true, onEndContact, set overlap = false. The first object is not moving (but not static) while other's body position is controlled by mouse click. The problem is this scenario is not work as expected, onBeginContact and onEndContact seem to work with every polygon parts of object's body, so the overlap assignment is not correct.

Is there any way to check 2 p2 body overlaping or not?

liv1n9 commented 5 years ago

I figured out the solution 👍 , instead of using boolean variable overlap, i use integer variable overlap, when onBeginContact i increase overlap by 1, when onEndContact i decrease overlap by 1. So two objects overlap when variable overlap > 0, otherwise they are not overlap.