Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render tilemap when camera outside of world bounds, layer wrapping #851

Merged
merged 1 commit into from
Jun 10, 2014

Conversation

jotson
Copy link
Contributor

@jotson jotson commented May 27, 2014

This changes TilemapLayer rendering so that it is possible to use them with an unbounded camera (a camera that can move beyond the world boundaries). Currently, when an unbounded camera moves outside of the world, tilemaps start acting weird because they only render themselves strictly within the world limits. With this change, the tilemap will continue scrolling and show empty space beyond its edge.

I also added a "wrap" property. When that is true, the map is rendered as if it is on the surface of a toroid (donut) instead of a plane. This allows for games that seamlessly scroll from one edge to the opposite edge of the world without noticing the transition.

Here's an example of this in action. In this example, the world, the map, and the stage are all 640x640 pixels: https://dl.dropboxusercontent.com/u/7063628/phaser-wrap/example.html

This is compatible with the current implementation with bounded cameras. The camera stops at the world edge and the game works exactly as before. Also, the "wrap" function isn't perfect: it only works correctly when the map is the same size as the world.

The renderDebug diff shows a bunch of changes because of an extra indent from adding if (this._column).

Not sure if this is a good idea or not. But I need it for a game I'm working on so here it is. :-)

Prior to this change, TilemapLayers always restricted themselves to
rendering strictly within the world bounds. If the camera was allowed
to go beyond the world bounds, then the tilemap would appear to stop
scrolling once the camera hit the world edge. This allows the tilemap
to continue scrolling, showing empty space beyond the edge of the map.

Additionally, when the new "wrap" parameter is true, the tilemap will
render its opposite edge in the empty space. This simulates the map as
if it was the surface of a toroid (donut) rather than a flat plane.
photonstorm added a commit that referenced this pull request Jun 10, 2014
Render tilemap when camera outside of world bounds, layer wrapping
@photonstorm photonstorm merged commit fddd1e9 into phaserjs:dev Jun 10, 2014
@photonstorm
Copy link
Collaborator

Nice one 👍

photonstorm added a commit that referenced this pull request Jun 10, 2014
… can move beyond the world boundaries). Currently, when an unbounded camera moves outside of the world, tilemaps start acting weird because they only render themselves strictly within the world limits. With this change, the tilemap will continue scrolling and show empty space beyond its edge (thanks @jotson #851)

TilemapLayer.wrap property - if true the map is rendered as if it is on the surface of a toroid (donut) instead of a plane. This allows for games that seamlessly scroll from one edge to the opposite edge of the world without noticing the transition. Note that the World size must match the Map size (thanks @jotson #851)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants