mirror of
https://github.com/wassname/phaser.git
synced 2026-07-03 17:10:40 +08:00
Tilemap.createCollisionObjects will parse Tiled data for objectgroups and convert polyline instances into physics objects you can collide with in the world.
After defining tiles that collide on a Tilemap, you need to call Tilemap.generateCollisionData(layer) to populate the physics world with the data required. Debug.renderPhysicsBody updated to take camera location and body rotation into account. Body movement functions put back to velocity :) Updated to latest dev version of pixi and latest p2.js Updated docs
This commit is contained in:
+14
-20
@@ -717,23 +717,24 @@ Phaser.Utils.Debug.prototype = {
|
||||
var shapeAngles = body.data.shapeAngles;
|
||||
|
||||
var i = shapes.length;
|
||||
var x = this.game.math.p2px(body.data.position[0]);
|
||||
var y = this.game.math.p2px(body.data.position[1]);
|
||||
var x = this.game.math.p2px(body.data.position[0]) - this.game.camera.view.x;
|
||||
var y = this.game.math.p2px(body.data.position[1]) - this.game.camera.view.y;
|
||||
var angle = body.data.angle;
|
||||
|
||||
while (i--)
|
||||
{
|
||||
if (shapes[i] instanceof p2.Rectangle)
|
||||
{
|
||||
this.renderShapeRectangle(shapes[i], x, y, angle);
|
||||
this.renderShapeRectangle(x, y, angle, shapes[i], shapeOffsets[i], shapeAngles[i]);
|
||||
}
|
||||
else if (shapes[i] instanceof p2.Line)
|
||||
{
|
||||
this.renderShapeLine(x, y, shapes[i], shapeOffsets[i], shapeAngles[i]);
|
||||
this.renderShapeLine(x, y, angle, shapes[i], shapeOffsets[i], shapeAngles[i]);
|
||||
}
|
||||
else if (shapes[i] instanceof p2.Convex)
|
||||
// else if (shapes[i] instanceof p2.Convex)
|
||||
else
|
||||
{
|
||||
this.renderShapeConvex(x, y, shapes[i], shapeOffsets[i], shapeAngles[i]);
|
||||
this.renderShapeConvex(x, y, angle, shapes[i], shapeOffsets[i], shapeAngles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -748,7 +749,7 @@ Phaser.Utils.Debug.prototype = {
|
||||
* @param {number} y - The y coordinate of the Body to translate to.
|
||||
* @param {number} angle - The angle of the Body to rotate to.
|
||||
*/
|
||||
renderShapeRectangle: function (shape, x, y, angle) {
|
||||
renderShapeRectangle: function (x, y, bodyAngle, shape, offset, angle) {
|
||||
|
||||
var w = this.game.math.p2px(shape.width);
|
||||
var h = this.game.math.p2px(shape.height);
|
||||
@@ -756,9 +757,8 @@ Phaser.Utils.Debug.prototype = {
|
||||
|
||||
this.context.beginPath();
|
||||
this.context.save();
|
||||
this.context.translate(x, y);
|
||||
this.context.rotate(angle);
|
||||
this.context.lineWidth = 0.5;
|
||||
this.context.translate(x + this.game.math.p2px(offset[0]), y + this.game.math.p2px(offset[1]));
|
||||
this.context.rotate(bodyAngle + angle);
|
||||
|
||||
this.context.moveTo(this.game.math.p2px(points[0][0]), this.game.math.p2px(points[0][1]));
|
||||
|
||||
@@ -781,18 +781,13 @@ Phaser.Utils.Debug.prototype = {
|
||||
* @param {number} offset -
|
||||
* @param {number} angle -
|
||||
*/
|
||||
renderShapeLine: function (x, y, shape, offset, angle) {
|
||||
renderShapeLine: function (x, y, bodyAngle, shape, offset, angle) {
|
||||
|
||||
// var w = this.game.math.p2px(shape.width);
|
||||
// var h = this.game.math.p2px(shape.height);
|
||||
// var points = shape.vertices;
|
||||
|
||||
this.context.beginPath();
|
||||
this.context.save();
|
||||
this.context.translate(x, y);
|
||||
this.context.rotate(angle);
|
||||
this.context.rotate(bodyAngle + angle);
|
||||
this.context.lineWidth = 0.5;
|
||||
// this.context.moveTo(this.game.math.p2px(points[0][0]), this.game.math.p2px(points[0][1]));
|
||||
this.context.moveTo(0, 0);
|
||||
this.context.lineTo(this.game.math.p2px(shape.length), 0);
|
||||
this.context.closePath();
|
||||
@@ -808,15 +803,14 @@ Phaser.Utils.Debug.prototype = {
|
||||
* @param {number} y - The y coordinate of the Body to translate to.
|
||||
* @param {number} angle - The angle of the Body to rotate to.
|
||||
*/
|
||||
renderShapeConvex: function (x, y, shape, offset, angle) {
|
||||
renderShapeConvex: function (x, y, bodyAngle, shape, offset, angle) {
|
||||
|
||||
var points = shape.vertices;
|
||||
|
||||
this.context.beginPath();
|
||||
this.context.save();
|
||||
this.context.translate(x + this.game.math.p2px(offset[0]), y + this.game.math.p2px(offset[1]));
|
||||
this.context.rotate(angle);
|
||||
this.context.lineWidth = 0.5;
|
||||
this.context.rotate(bodyAngle + angle);
|
||||
|
||||
this.context.moveTo(this.game.math.p2px(points[0][0]), this.game.math.p2px(points[0][1]));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user