mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
World.wrap will take a game object and if its x/y coordinates fall outside of the world bounds it will be repositioned on the opposite side, for a wrap-around effect.
This commit is contained in:
parent
089dfbb960
commit
b77c034f61
2 changed files with 61 additions and 1 deletions
|
@ -76,11 +76,12 @@ Version 2.0.4 - "Mos Shirare" - in development
|
|||
* Key.reset has a new `hard` parameter which controls the severity of the reset. A soft reset doesn't remove any callbacks or event listeners.
|
||||
* InputManager.resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.
|
||||
* Group.resetCursor will reset the Group cursor back to the start of the group, or to the given index value.
|
||||
* World.wrap will take a game object and if its x/y coordinates fall outside of the world bounds it will be repositioned on the opposite side, for a wrap-around effect.
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* The main Timer loop could incorrectly remove TimeEvent if a new one was added specifically during an event callback (thanks @garyyeap, fix #710)
|
||||
* The main Timer loop could incorrectly remove a TimerEvent if a new one was added specifically during an event callback (thanks @garyyeap, fix #710)
|
||||
* Fixed the use of the destroy parameter in Group.removeAll and related functions (thanks @AnderbergE, fix #717)
|
||||
* P2.World.convertTilemap now correctly checks the collides parameter of the tiles as it converts them.
|
||||
* Animation.destroy didn't correctly clear the onStart, onLoop and onComplete signals.
|
||||
|
|
|
@ -104,6 +104,65 @@ Phaser.World.prototype.shutdown = function () {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* This will take the given game object and check if its x/y coordinates fall outside of the world bounds.
|
||||
* If they do it will reposition the object to the opposite side of the world, creating a wrap-around effect.
|
||||
*
|
||||
* @method Phaser.World#wrap
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.TileSprite|Phaser.Text} sprite - The object you wish to wrap around the world bounds.
|
||||
* @param {number} [padding=0] - Extra padding added equally to the sprite.x and y coordinates before checking if within the world bounds. Ignored if useBounds is true.
|
||||
* @param {boolean} [useBounds=false] - If useBounds is false wrap checks the object.x/y coordinates. If true it does a more accurate bounds check, which is more expensive.
|
||||
*/
|
||||
Phaser.World.prototype.wrap = function (sprite, padding, useBounds) {
|
||||
|
||||
if (typeof padding === 'undefined') { padding = 0; }
|
||||
if (typeof useBounds === 'undefined') { useBounds = false; }
|
||||
|
||||
if (!useBounds)
|
||||
{
|
||||
if (sprite.x + padding < this.bounds.x)
|
||||
{
|
||||
sprite.x = this.bounds.right + padding;
|
||||
}
|
||||
else if (sprite.x - padding > this.bounds.right)
|
||||
{
|
||||
sprite.x = this.bounds.left - padding;
|
||||
}
|
||||
|
||||
if (sprite.y + padding < this.bounds.top)
|
||||
{
|
||||
sprite.y = this.bounds.bottom + padding;
|
||||
}
|
||||
else if (sprite.y - padding > this.bounds.bottom)
|
||||
{
|
||||
sprite.y = this.bounds.top - padding;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.getBounds();
|
||||
|
||||
if (sprite._currentBounds.right < this.bounds.x)
|
||||
{
|
||||
sprite.x = this.bounds.right;
|
||||
}
|
||||
else if (sprite._currentBounds.x > this.bounds.right)
|
||||
{
|
||||
sprite.x = this.bounds.left;
|
||||
}
|
||||
|
||||
if (sprite._currentBounds.bottom < this.bounds.top)
|
||||
{
|
||||
sprite.y = this.bounds.bottom;
|
||||
}
|
||||
else if (sprite._currentBounds.top > this.bounds.bottom)
|
||||
{
|
||||
sprite.y = this.bounds.top;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Phaser.World#width
|
||||
* @property {number} width - Gets or sets the current width of the game world.
|
||||
|
|
Loading…
Reference in a new issue