mirror of
https://github.com/wassname/phaser.git
synced 2026-07-24 13:10:53 +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:
+104
-15
@@ -58,6 +58,10 @@
|
||||
<a href="Phaser.BitmapData.html">BitmapData</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapFont.html">BitmapFont</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapText.html">BitmapText</a>
|
||||
</li>
|
||||
@@ -90,10 +94,6 @@
|
||||
<a href="Phaser.Device.html">Device</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.DOMSprite.html">DOMSprite</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Easing.html">Easing</a>
|
||||
</li>
|
||||
@@ -142,6 +142,10 @@
|
||||
<a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Ellipse.html">Ellipse</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Events.html">Events</a>
|
||||
</li>
|
||||
@@ -250,10 +254,6 @@
|
||||
<a href="Phaser.Physics.Arcade.html">Arcade</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Plugin.html">Plugin</a>
|
||||
</li>
|
||||
@@ -314,6 +314,10 @@
|
||||
<a href="Phaser.Sprite.html">Sprite</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.SpriteBatch.html">SpriteBatch</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Stage.html">Stage</a>
|
||||
</li>
|
||||
@@ -412,6 +416,10 @@
|
||||
<a href="global.html#canUseNewCanvasBlendModes">canUseNewCanvasBlendModes</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#getBounds">getBounds</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#getNextPowerOfTwo">getNextPowerOfTwo</a>
|
||||
</li>
|
||||
@@ -451,6 +459,7 @@
|
||||
<article>
|
||||
<pre class="sunlight-highlight-javascript linenums">/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @author Adrien Brault <adrien.brault@gmail.com>
|
||||
* @copyright 2014 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
@@ -458,8 +467,8 @@
|
||||
/**
|
||||
* Creates a new Polygon. You have to provide a list of points.
|
||||
* This can be an array of Points that form the polygon, a flat array of numbers that will be interpreted as [x,y, x,y, ...],
|
||||
* or the arguments passed can be all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the
|
||||
* arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are numbers.
|
||||
* or the arguments passed can be all the points of the polygon e.g. `new Phaser.Polygon(new Phaser.Point(), new Phaser.Point(), ...)`, or the
|
||||
* arguments passed can be flat x,y values e.g. `new Phaser.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are numbers.
|
||||
*
|
||||
* @class Phaser.Polygon
|
||||
* @classdesc The polygon represents a list of orderded points in space
|
||||
@@ -468,17 +477,97 @@
|
||||
*/
|
||||
Phaser.Polygon = function (points) {
|
||||
|
||||
PIXI.Polygon.call(this, points);
|
||||
|
||||
/**
|
||||
* @property {number} type - The base object type.
|
||||
*/
|
||||
this.type = Phaser.POLYGON;
|
||||
|
||||
//if points isn't an array, use arguments as the array
|
||||
if (!(points instanceof Array))
|
||||
{
|
||||
points = Array.prototype.slice.call(arguments);
|
||||
}
|
||||
|
||||
//if this is a flat array of numbers, convert it to points
|
||||
if (typeof points[0] === 'number')
|
||||
{
|
||||
var p = [];
|
||||
|
||||
for (var i = 0, len = points.length; i < len; i += 2)
|
||||
{
|
||||
p.push(new Phaser.Point(points[i], points[i + 1]));
|
||||
}
|
||||
|
||||
points = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {array<Phaser.Point>|array<number>} points - The array of Points.
|
||||
*/
|
||||
this.points = points;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Polygon.prototype = Object.create(PIXI.Polygon.prototype);
|
||||
Phaser.Polygon.prototype.constructor = Phaser.Polygon;</pre>
|
||||
Phaser.Polygon.prototype = {
|
||||
|
||||
/**
|
||||
* Creates a clone of this polygon.
|
||||
*
|
||||
* @method Phaser.Polygon#clone
|
||||
* @return {Phaser.Polygon} A copy of the polygon.
|
||||
*/
|
||||
clone: function () {
|
||||
|
||||
var points = [];
|
||||
|
||||
for (var i=0; i < this.points.length; i++)
|
||||
{
|
||||
points.push(this.points[i].clone());
|
||||
}
|
||||
|
||||
return new Phaser.Polygon(points);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the x and y coordinates are contained within this polygon.
|
||||
*
|
||||
* @method Phaser.Polygon#contains
|
||||
* @param {number} x - The X value of the coordinate to test.
|
||||
* @param {number} y - The Y value of the coordinate to test.
|
||||
* @return {boolean} True if the coordinates are within this polygon, otherwise false.
|
||||
*/
|
||||
contains: function (x, y) {
|
||||
|
||||
var inside = false;
|
||||
|
||||
// use some raycasting to test hits https://github.com/substack/point-in-polygon/blob/master/index.js
|
||||
for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++)
|
||||
{
|
||||
var xi = this.points[i].x;
|
||||
var yi = this.points[i].y;
|
||||
var xj = this.points[j].x;
|
||||
var yj = this.points[j].y;
|
||||
|
||||
var intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
||||
|
||||
if (intersect)
|
||||
{
|
||||
inside = true;
|
||||
}
|
||||
}
|
||||
|
||||
return inside;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Polygon.prototype.constructor = Phaser.Polygon;
|
||||
|
||||
// Because PIXI uses its own Polygon, we'll replace it with ours to avoid duplicating code or confusion.
|
||||
PIXI.Polygon = Phaser.Polygon;
|
||||
</pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
@@ -499,7 +588,7 @@ Phaser.Polygon.prototype.constructor = Phaser.Polygon;</pre>
|
||||
|
||||
<span class="jsdoc-message">
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
|
||||
on Sat Feb 08 2014 07:19:40 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
on Tue Feb 18 2014 03:01:17 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user