You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
world.wrap do not use world coordinates. So after scaling world, wrap is not working properly.
This code corrects error:
/**
* 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.
* If sprite has a P2 body then the body (sprite.body) should be passed as first parameter to the function.
*
* @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.
* @param {boolean} [horizontal=true] - If horizontal is false, wrap will not wrap the object.x coordinates horizontally.
* @param {boolean} [vertical=true] - If vertical is false, wrap will not wrap the object.y coordinates vertically.
*/
Phaser.World.prototype.wrap = function (sprite, padding, useBounds, horizontal, vertical) {
if (padding === undefined) { padding = 0; }
if (useBounds === undefined) { useBounds = false; }
if (horizontal === undefined) { horizontal = true; }
if (vertical === undefined) { vertical = true; }
if (!useBounds)
{
if (horizontal && sprite.world.x + padding < this.bounds.x)
{
sprite.x = (sprite.x / sprite.world.x) * (this.bounds.right + padding);
}
else if (horizontal && sprite.world.x - padding > this.bounds.right)
{
sprite.x = (sprite.x / sprite.world.x) * (this.bounds.left - padding);
}
if (vertical && sprite.world.y + padding < this.bounds.top)
{
sprite.y = (sprite.y / sprite.world.y) * (this.bounds.bottom + padding);
}
else if (vertical && sprite.world.y - padding > this.bounds.bottom)
{
sprite.y = (sprite.y / sprite.world.y) * (this.bounds.top - padding);
}
}
else
{
sprite.getBounds();
if (horizontal)
{
if ((sprite.world.x + sprite._currentBounds.width) < this.bounds.x)
{
sprite.x = (sprite.x / sprite.world.x) * this.bounds.right;
}
else if (sprite.world.x > this.bounds.right)
{
sprite.x = (sprite.x / sprite.world.x) * this.bounds.left;
}
}
if (vertical)
{
if ((sprite.world.y + sprite._currentBounds.height) < this.bounds.top)
{
sprite.y = (sprite.y / sprite.world.y) * this.bounds.bottom;
}
else if (sprite.world.y > this.bounds.bottom)
{
sprite.y = (sprite.y / sprite.world.y) * this.bounds.top;
}
}
}
};
The text was updated successfully, but these errors were encountered:
I tried this code, scaled the world and it all went to hell when it tried wrapping. Possibly because of the Camera though, either way it didn't work quite right. I'm going to accept this as a limitation of the current method, and have updated the jsdocs accordingly.
world.wrap do not use world coordinates. So after scaling world, wrap is not working properly.
This code corrects error:
The text was updated successfully, but these errors were encountered: