mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
QuadTree deprecated and moved to plugins. Body.collideWorldBounds added back and working. CollisionGroups pretty much finished.
This commit is contained in:
parent
5968dd053b
commit
14646e811c
6 changed files with 69 additions and 30 deletions
|
@ -105,7 +105,6 @@ module.exports = function (grunt) {
|
|||
|
||||
'src/math/Math.js',
|
||||
'src/math/RandomDataGenerator.js',
|
||||
'src/math/QuadTree.js',
|
||||
|
||||
'src/net/Net.js',
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ Significant API changes:
|
|||
* World preUpdate, update and postUpdate have all been moved to Stage. So all children are updated regardless where on the display list they live.
|
||||
* Cache.getImageKeys and similar has been removed, please use Cache.getKeys(Phaser.Cache.IMAGE) instead, this now supports all 10 Cache data types.
|
||||
* After defining tiles that collide on a Tilemap, you need to call Tilemap.generateCollisionData(layer) to populate the physics world with the data required.
|
||||
* Phaser.QuadTree has been removed from core and moved to a plugin. It's no longer required, nor works with the physics system.
|
||||
|
||||
|
||||
New features:
|
||||
|
|
|
@ -151,7 +151,6 @@
|
|||
|
||||
<script src="$path/src/math/Math.js"></script>
|
||||
<script src="$path/src/math/RandomDataGenerator.js"></script>
|
||||
<script src="$path/src/math/QuadTree.js"></script>
|
||||
|
||||
<script src="$path/src/net/Net.js"></script>
|
||||
|
||||
|
|
|
@ -17,9 +17,6 @@ var angle = 0;
|
|||
var fireRate = 100;
|
||||
var nextFire = 0;
|
||||
var cursors;
|
||||
// var PLAYER;
|
||||
// var BULLET;
|
||||
// var WORLD;
|
||||
var boxes;
|
||||
var playerGroup;
|
||||
var bulletGroup;
|
||||
|
@ -44,31 +41,21 @@ function create() {
|
|||
bulletGroup = game.physics.createCollisionGroup();
|
||||
boxGroup = game.physics.createCollisionGroup();
|
||||
|
||||
// cannon.body.data.shapes[0].collisionGroup = PLAYER.mask;
|
||||
// cannon.body.data.shapes[0].collisionMask = game.physics.WORLD.mask;
|
||||
|
||||
cannon.body.setCollisionGroup(playerGroup);
|
||||
cannon.body.collides(boxGroup);
|
||||
|
||||
|
||||
boxes = game.add.group();
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
var box = boxes.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(100, 500), 'box');
|
||||
box.name = 'box' + i;
|
||||
box.scale.set(0.5);
|
||||
// box.scale.set(game.rnd.realInRange(0.2, 0.7));
|
||||
box.scale.set(game.rnd.realInRange(0.2, 0.7));
|
||||
box.physicsEnabled = true;
|
||||
box.body.setCollisionGroup(boxGroup);
|
||||
box.body.collides(playerGroup);
|
||||
box.body.collides(bulletGroup);
|
||||
// box.body.mass = 10;
|
||||
// box.body.setMaterial(boxMaterial);
|
||||
// box.body.fixedRotation = true;
|
||||
box.body.collides( [ playerGroup, bulletGroup, boxGroup ]);
|
||||
}
|
||||
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
@ -87,7 +74,7 @@ function fire() {
|
|||
bullet.exists = true;
|
||||
bullet.position.set(cannon.x, cannon.y);
|
||||
bullet.physicsEnabled = true;
|
||||
|
||||
bullet.body.collideWorldBounds = false;
|
||||
bullet.body.rotation = cannon.rotation + game.math.degToRad(90);
|
||||
|
||||
var magnitude = game.math.px2p(-500);
|
||||
|
@ -98,9 +85,6 @@ function fire() {
|
|||
|
||||
bullet.body.setCollisionGroup(bulletGroup);
|
||||
bullet.body.collides(boxGroup);
|
||||
|
||||
// bullet.body.data.shapes[0].collisionGroup = BULLET;
|
||||
// bullet.body.data.shapes[0].collisionMask = WORLD | BULLET;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,13 @@ Phaser.Physics.Body = function (game, sprite, x, y, mass) {
|
|||
|
||||
Phaser.Physics.Body.prototype = {
|
||||
|
||||
/**
|
||||
* Sets the given CollisionGroup to be the collision group for all shapes in this Body, unless a shape is specified.
|
||||
*
|
||||
* @method Phaser.Physics.Body#setCollisionGroup
|
||||
* @param {Phaser.Physics.CollisionGroup|array} group - The Collision Group that this Bodies shapes will use.
|
||||
* @param {p2.Shape} [shape] - An optional Shape. If not provided the collision group will be added to all Shapes in this Body.
|
||||
*/
|
||||
setCollisionGroup: function (group, shape) {
|
||||
|
||||
if (typeof shape === 'undefined')
|
||||
|
@ -107,19 +114,70 @@ Phaser.Physics.Body.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Adds the given CollisionGroup to the list of groups that this body will collide with and updates the collision mask.
|
||||
* Clears the collision data from the shapes in this Body. Optionally clears Group and/or Mask.
|
||||
*
|
||||
* @method Phaser.Physics.Body#clearCollision
|
||||
* @param {boolean} [clearGroup=true] - Clear the collisionGroup value from the shape/s?
|
||||
* @param {boolean} [clearMask=true] - Clear the collisionMask value from the shape/s?
|
||||
* @param {p2.Shape} [shape] - An optional Shape. If not provided the collision data will be cleared from all Shapes in this Body.
|
||||
*/
|
||||
clearCollision: function (clearGroup, clearMask, shape) {
|
||||
|
||||
if (typeof shape === 'undefined')
|
||||
{
|
||||
for (var i = this.data.shapes.length - 1; i >= 0; i--)
|
||||
{
|
||||
if (clearGroup)
|
||||
{
|
||||
this.data.shapes[i].collisionGroup = null;
|
||||
}
|
||||
|
||||
if (clearMask)
|
||||
{
|
||||
this.data.shapes[i].collisionMask = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clearGroup)
|
||||
{
|
||||
shapes.collisionGroup = null;
|
||||
}
|
||||
|
||||
if (clearMask)
|
||||
{
|
||||
shapes.collisionMask = null;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds the given CollisionGroup, or array of CollisionGroups, to the list of groups that this body will collide with and updates the collision masks.
|
||||
*
|
||||
* @method Phaser.Physics.Body#collides
|
||||
* @param {Phaser.Physics.CollisionGroup} group - The Collision Group that this Bodies shapes will collide with.
|
||||
* @param {Phaser.Physics.CollisionGroup|array} group - The Collision Group or Array of Collision Groups that this Bodies shapes will collide with.
|
||||
* @param {p2.Shape} [shape] - An optional Shape. If not provided the collision mask will be added to all Shapes in this Body.
|
||||
*/
|
||||
collides: function (group, shape) {
|
||||
|
||||
// TODO: group can be an array
|
||||
|
||||
if (this.collidesWith.indexOf(group) === -1)
|
||||
if (Array.isArray(group))
|
||||
{
|
||||
this.collidesWith.push(group);
|
||||
for (var i = 0; i < group.length; i++)
|
||||
{
|
||||
if (this.collidesWith.indexOf(group[i]) === -1)
|
||||
{
|
||||
this.collidesWith.push(group[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.collidesWith.indexOf(group) === -1)
|
||||
{
|
||||
this.collidesWith.push(group);
|
||||
}
|
||||
}
|
||||
|
||||
var mask = 0;
|
||||
|
@ -146,8 +204,6 @@ Phaser.Physics.Body.prototype = {
|
|||
shape.collisionMask = mask;
|
||||
}
|
||||
|
||||
console.log('collides', this.sprite.name, group, mask);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue