forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The way the collision process callback works has changed significantl…
…y and now works as originally intended. The World level quadtree is no longer created, they are now built and ripped down each time you collide a Group, this helps collision accuracy. Bodies are no longer added to a world quadtree, so have had all of their quadtree properties removed such as skipQuadtree, quadTreeIndex, etc. QuadTree.populate - you can pass it a Group and it'll automatically insert all of the children ready for inspection. Removed ArcadePhysics binding to the QuadTree, so it can now be used independantly of the physics system.
- Loading branch information
1 parent
17af96d
commit 011d2d8
Showing
11 changed files
with
292 additions
and
625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); | ||
|
||
function preload() { | ||
|
||
game.load.image('atari', 'assets/sprites/atari130xe.png'); | ||
game.load.image('mushroom', 'assets/sprites/mushroom2.png'); | ||
|
||
} | ||
|
||
var sprite1; | ||
var sprite2; | ||
|
||
function create() { | ||
|
||
game.stage.backgroundColor = '#2d2d2d'; | ||
|
||
// This will check Sprite vs. Sprite collision using a custom process callback | ||
sprite1 = game.add.sprite(0, 200, 'atari'); | ||
sprite2 = game.add.sprite(750, 220, 'mushroom'); | ||
|
||
// We'll use random velocities so we can test it in our processCallback | ||
sprite1.body.velocity.x = 50 + Math.random() * 100; | ||
sprite2.body.velocity.x = -(50 + Math.random() * 100); | ||
|
||
} | ||
|
||
function update() { | ||
|
||
game.physics.collide(sprite1, sprite2, collisionCallback, processCallback, this); | ||
|
||
} | ||
|
||
function processCallback (obj1, obj2) { | ||
|
||
// This function can perform your own additional checks on the 2 objects that collided. | ||
// For example you could test for velocity, health, etc. | ||
// This function needs to return either true or false. If it returns true then collision carries on (separating the two objects). | ||
// If it returns false the collision is assumed to have failed and aborts, no further checks or separation happen. | ||
|
||
if (obj1.body.speed > obj2.body.speed) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
|
||
} | ||
|
||
function collisionCallback (obj1, obj2) { | ||
|
||
game.stage.backgroundColor = '#992d2d'; | ||
|
||
} | ||
|
||
function render() { | ||
|
||
game.debug.renderText('The processCallback will only collide if sprite1 is going fastest.', 32, 32); | ||
game.debug.renderText('Sprite 1 speed: ' + sprite1.body.speed, 32, 64); | ||
game.debug.renderText('Sprite 2 speed: ' + sprite2.body.speed, 32, 96); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.