mirror of
https://github.com/wassname/phaser.git
synced 2026-07-11 00:40:20 +08:00
ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.
This commit is contained in:
@@ -67,6 +67,12 @@ Phaser.Stage = function (game, width, height) {
|
||||
*/
|
||||
this.aspectRatio = width / height;
|
||||
|
||||
/**
|
||||
* @property {boolean} disableVisibilityChange - By default if the browser tab loses focus the game will pause. You can stop that behaviour by setting this property to true.
|
||||
* @default
|
||||
*/
|
||||
this.disableVisibilityChange = false;
|
||||
|
||||
/**
|
||||
* @property {number} _nextOffsetCheck - The time to run the next offset check.
|
||||
* @private
|
||||
|
||||
@@ -51,8 +51,110 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
|
||||
*/
|
||||
this.tilePosition = new Phaser.Point(0, 0);
|
||||
|
||||
this.body.width = width;
|
||||
this.body.height = height;
|
||||
|
||||
};
|
||||
|
||||
Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype);
|
||||
Phaser.TileSprite.prototype.constructor = Phaser.TileSprite;
|
||||
|
||||
/**
|
||||
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
|
||||
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
|
||||
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
|
||||
* @name Phaser.TileSprite#angle
|
||||
* @property {number} angle - Gets or sets the Sprites angle of rotation in degrees.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, 'angle', {
|
||||
|
||||
get: function() {
|
||||
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TileSprite#frame
|
||||
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "frame", {
|
||||
|
||||
get: function () {
|
||||
return this.animations.frame;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.animations.frame = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TileSprite#frameName
|
||||
* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "frameName", {
|
||||
|
||||
get: function () {
|
||||
return this.animations.frameName;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.animations.frameName = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TileSprite#inCamera
|
||||
* @property {boolean} inCamera - Is this sprite visible to the camera or not?
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "inCamera", {
|
||||
|
||||
get: function () {
|
||||
return this._cache.cameraVisible;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
|
||||
* activated for this Sprite instance and it will then start to process click/touch events and more.
|
||||
*
|
||||
* @name Phaser.TileSprite#inputEnabled
|
||||
* @property {boolean} inputEnabled - Set to true to allow this Sprite to receive input events, otherwise false.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "inputEnabled", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.input.enabled);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value)
|
||||
{
|
||||
if (this.input.enabled === false)
|
||||
{
|
||||
this.input.start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.input.enabled)
|
||||
{
|
||||
this.input.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -207,7 +207,7 @@ Phaser.Pointer.prototype = {
|
||||
}
|
||||
|
||||
// Fix to stop rogue browser plugins from blocking the visibility state event
|
||||
if (this.game.paused === true && this.game.stage.scale.incorrectOrientation === false)
|
||||
if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.stage.scale.incorrectOrientation === false)
|
||||
{
|
||||
this.game.paused = false;
|
||||
return this;
|
||||
|
||||
@@ -396,18 +396,22 @@ Phaser.Loader.prototype = {
|
||||
* @param {string} url - URL of the tileset.
|
||||
* @param {number} tileWidth - Width of each single tile in pixels.
|
||||
* @param {number} tileHeight - Height of each single tile in pixels.
|
||||
* @param {number} [tileMax=-1] - How many tiles in this tileset. If not specified it will divide the whole image into tiles.
|
||||
* @param {number} [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here.
|
||||
* @param {number} [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here.
|
||||
* @param {number} [rows=-1] - How many tiles are placed horizontally in each row? If -1 it will calculate rows by dividing the image width by tileWidth.
|
||||
* @param {number} [columns=-1] - How many tiles are placed vertically in each column? If -1 it will calculate columns by dividing the image height by tileHeight.
|
||||
* @param {number} [limit=-1] - The maximum number of tiles to extract from the image. If -1 it will extract rows * columns worth, otherwise you can set a lower limit value.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
tileset: function (key, url, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
|
||||
tileset: function (key, url, tileWidth, tileHeight, tileMargin, tileSpacing, rows, columns, limit) {
|
||||
|
||||
if (typeof tileMax === "undefined") { tileMax = -1; }
|
||||
if (typeof tileMargin === "undefined") { tileMargin = 0; }
|
||||
if (typeof tileSpacing === "undefined") { tileSpacing = 0; }
|
||||
if (typeof rows === "undefined") { rows = -1; }
|
||||
if (typeof columns === "undefined") { columns = -1; }
|
||||
if (typeof limit === "undefined") { limit = -1; }
|
||||
|
||||
this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMax: tileMax, tileMargin: tileMargin, tileSpacing: tileSpacing });
|
||||
this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMargin: tileMargin, tileSpacing: tileSpacing, rows: rows, columns: columns, limit: limit });
|
||||
|
||||
return this;
|
||||
|
||||
|
||||
@@ -306,9 +306,9 @@ Phaser.Physics.Arcade.prototype = {
|
||||
if (object1 && object2 && object1.exists && object2.exists)
|
||||
{
|
||||
// SPRITES
|
||||
if (object1.type == Phaser.SPRITE)
|
||||
if (object1.type == Phaser.SPRITE || object1.type == Phaser.TILESPRITE)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsSprite(object1, object2, overlapCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -320,7 +320,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// GROUPS
|
||||
else if (object1.type == Phaser.GROUP)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -332,7 +332,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// EMITTER
|
||||
else if (object1.type == Phaser.EMITTER)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -482,12 +482,10 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// Only collide valid objects
|
||||
if (object1 && object2 && object1.exists && object2.exists)
|
||||
{
|
||||
// Can expand to support Buttons, Text, etc at a later date. For now these are the essentials.
|
||||
|
||||
// SPRITES
|
||||
if (object1.type == Phaser.SPRITE)
|
||||
if (object1.type == Phaser.SPRITE || object1.type == Phaser.TILESPRITE)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -503,7 +501,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// GROUPS
|
||||
else if (object1.type == Phaser.GROUP)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -519,7 +517,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// TILEMAP LAYERS
|
||||
else if (object1.type == Phaser.TILEMAPLAYER)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -531,7 +529,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// EMITTER
|
||||
else if (object1.type == Phaser.EMITTER)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ PIXI.WebGLRenderGroup = function(gl, transparent)
|
||||
|
||||
this.batchs = [];
|
||||
this.toRemove = [];
|
||||
console.log(this.transparent)
|
||||
this.filterManager = new PIXI.WebGLFilterManager(this.transparent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user