wrap(sprite, padding, useBounds, horizontal, vertical)
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.
Please understand there are limitations to this method. For example if you have scaled the World
then objects won't always be re-positioned correctly, and you'll need to employ your own wrapping function.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
sprite | Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Text | The object you wish to wrap around the world bounds. | ||
padding | number | <optional> | 0 | Extra padding added equally to the sprite.x and y coordinates before checking if within the world bounds. Ignored if useBounds is true. |
useBounds | boolean | <optional> | 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. |
horizontal | boolean | <optional> | true | If horizontal is false, wrap will not wrap the object.x coordinates horizontally. |
vertical | boolean | <optional> | true | If vertical is false, wrap will not wrap the object.y coordinates vertically. |
- Source code: core/World.js (Line 170)
Please login to continue.