mirror of
https://github.com/wassname/phaser.git
synced 2026-06-30 16:40:20 +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:
+131
-18
@@ -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>
|
||||
@@ -558,10 +566,22 @@ Phaser.InputHandler = function (sprite) {
|
||||
this.snapOffsetY = 0;
|
||||
|
||||
/**
|
||||
* @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
|
||||
* Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite.
|
||||
* The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value.
|
||||
* Warning: This is expensive, especially on mobile (where it's not even needed!) so only enable if required. Also see the less-expensive InputHandler.pixelPerfectClick.
|
||||
* @property {number} pixelPerfectOver - Use a pixel perfect check when testing for pointer over.
|
||||
* @default
|
||||
*/
|
||||
this.pixelPerfect = false;
|
||||
this.pixelPerfectOver = false;
|
||||
|
||||
/**
|
||||
* Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite when it's clicked or touched.
|
||||
* The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value.
|
||||
* Warning: This is expensive so only enable if you really need it.
|
||||
* @property {number} pixelPerfectClick - Use a pixel perfect check when testing for clicks or touches on the Sprite.
|
||||
* @default
|
||||
*/
|
||||
this.pixelPerfectClick = false;
|
||||
|
||||
/**
|
||||
* @property {number} pixelPerfectAlpha - The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit.
|
||||
@@ -596,11 +616,15 @@ Phaser.InputHandler = function (sprite) {
|
||||
this.consumePointerEvent = false;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} _tempPoint - Description.
|
||||
* @property {Phaser.Point} _tempPoint - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._tempPoint = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {array} _pointerData - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._pointerData = [];
|
||||
|
||||
this._pointerData.push({
|
||||
@@ -741,10 +765,12 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
this.game.input.interactiveItems.remove(this);
|
||||
|
||||
this.stop();
|
||||
|
||||
this._pointerData.length = 0;
|
||||
this.boundsRect = null;
|
||||
this.boundsSprite = null;
|
||||
this.sprite = null;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -935,6 +961,36 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given pointer is over this Sprite and can click it.
|
||||
* @method Phaser.InputHandler#checkPointerDown
|
||||
* @param {Phaser.Pointer} pointer
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkPointerDown: function (pointer) {
|
||||
|
||||
if (this.enabled === false || this.sprite.visible === false || this.sprite.parent.visible === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Need to pass it a temp point, in case we need it again for the pixel check
|
||||
if (this.game.input.hitTest(this.sprite, pointer, this._tempPoint))
|
||||
{
|
||||
if (this.pixelPerfectClick)
|
||||
{
|
||||
return this.checkPixel(this._tempPoint.x, this._tempPoint.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given pointer is over this Sprite.
|
||||
* @method Phaser.InputHandler#checkPointerOver
|
||||
@@ -951,7 +1007,7 @@ Phaser.InputHandler.prototype = {
|
||||
// Need to pass it a temp point, in case we need it again for the pixel check
|
||||
if (this.game.input.hitTest(this.sprite, pointer, this._tempPoint))
|
||||
{
|
||||
if (this.pixelPerfect)
|
||||
if (this.pixelPerfectOver)
|
||||
{
|
||||
return this.checkPixel(this._tempPoint.x, this._tempPoint.y);
|
||||
}
|
||||
@@ -971,15 +1027,35 @@ Phaser.InputHandler.prototype = {
|
||||
* @method Phaser.InputHandler#checkPixel
|
||||
* @param {number} x - The x coordinate to check.
|
||||
* @param {number} y - The y coordinate to check.
|
||||
* @param {Phaser.Pointer} [pointer] - The pointer to get the x/y coordinate from if not passed as the first two parameters.
|
||||
* @return {boolean} true if there is the alpha of the pixel is >= InputHandler.pixelPerfectAlpha
|
||||
*/
|
||||
checkPixel: function (x, y) {
|
||||
checkPixel: function (x, y, pointer) {
|
||||
|
||||
// Grab a pixel from our image into the hitCanvas and then test it
|
||||
if (this.sprite.texture.baseTexture.source)
|
||||
{
|
||||
this.game.input.hitContext.clearRect(0, 0, 1, 1);
|
||||
|
||||
if (x === null && y === null)
|
||||
{
|
||||
// Use the pointer parameter
|
||||
this.game.input.getLocalPosition(this.sprite, pointer, this._tempPoint);
|
||||
|
||||
var x = this._tempPoint.x;
|
||||
var y = this._tempPoint.y;
|
||||
}
|
||||
|
||||
if (this.sprite.anchor.x !== 0)
|
||||
{
|
||||
x -= -this.sprite.texture.frame.width * this.sprite.anchor.x;
|
||||
}
|
||||
|
||||
if (this.sprite.anchor.y !== 0)
|
||||
{
|
||||
y -= -this.sprite.texture.frame.height * this.sprite.anchor.y;
|
||||
}
|
||||
|
||||
x += this.sprite.texture.frame.x;
|
||||
y += this.sprite.texture.frame.y;
|
||||
|
||||
@@ -1000,10 +1076,17 @@ Phaser.InputHandler.prototype = {
|
||||
/**
|
||||
* Update.
|
||||
* @method Phaser.InputHandler#update
|
||||
* @protected
|
||||
* @param {Phaser.Pointer} pointer
|
||||
*/
|
||||
update: function (pointer) {
|
||||
|
||||
if (this.sprite === null)
|
||||
{
|
||||
// Abort. We've been destroyed.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.enabled === false || this.sprite.visible === false || (this.sprite.group && this.sprite.group.visible === false))
|
||||
{
|
||||
this._pointerOutHandler(pointer);
|
||||
@@ -1038,6 +1121,12 @@ Phaser.InputHandler.prototype = {
|
||||
*/
|
||||
_pointerOverHandler: function (pointer) {
|
||||
|
||||
if (this.sprite === null)
|
||||
{
|
||||
// Abort. We've been destroyed.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._pointerData[pointer.id].isOver === false)
|
||||
{
|
||||
this._pointerData[pointer.id].isOver = true;
|
||||
@@ -1053,6 +1142,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
this.sprite.events.onInputOver.dispatch(this.sprite, pointer);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1063,6 +1153,12 @@ Phaser.InputHandler.prototype = {
|
||||
*/
|
||||
_pointerOutHandler: function (pointer) {
|
||||
|
||||
if (this.sprite === null)
|
||||
{
|
||||
// Abort. We've been destroyed.
|
||||
return;
|
||||
}
|
||||
|
||||
this._pointerData[pointer.id].isOver = false;
|
||||
this._pointerData[pointer.id].isOut = true;
|
||||
this._pointerData[pointer.id].timeOut = this.game.time.now;
|
||||
@@ -1087,8 +1183,19 @@ Phaser.InputHandler.prototype = {
|
||||
*/
|
||||
_touchedHandler: function (pointer) {
|
||||
|
||||
if (this.sprite === null)
|
||||
{
|
||||
// Abort. We've been destroyed.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._pointerData[pointer.id].isDown === false && this._pointerData[pointer.id].isOver === true)
|
||||
{
|
||||
if (this.pixelPerfectClick && !this.checkPixel(null, null, pointer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._pointerData[pointer.id].isDown = true;
|
||||
this._pointerData[pointer.id].isUp = false;
|
||||
this._pointerData[pointer.id].timeDown = this.game.time.now;
|
||||
@@ -1119,6 +1226,12 @@ Phaser.InputHandler.prototype = {
|
||||
*/
|
||||
_releasedHandler: function (pointer) {
|
||||
|
||||
if (this.sprite === null)
|
||||
{
|
||||
// Abort. We've been destroyed.
|
||||
return;
|
||||
}
|
||||
|
||||
// If was previously touched by this Pointer, check if still is AND still over this item
|
||||
if (this._pointerData[pointer.id].isDown && pointer.isUp)
|
||||
{
|
||||
@@ -1262,7 +1375,7 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* Returns true if the pointer has touched or clicked on the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @method Phaser.InputHandler#justPressed
|
||||
* @param {Phaser.Pointer} pointer
|
||||
* @param {number} delay - The time below which the pointer is considered as just over.
|
||||
@@ -1278,7 +1391,7 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* Returns true if the pointer was touching this Sprite, but has been released within the specified delay time (defaults to 500ms, half a second)
|
||||
* @method Phaser.InputHandler#justReleased
|
||||
* @param {Phaser.Pointer} pointer
|
||||
* @param {number} delay - The time below which the pointer is considered as just out.
|
||||
@@ -1649,7 +1762,7 @@ Phaser.InputHandler.prototype.constructor = Phaser.InputHandler;
|
||||
|
||||
<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