Nepoxx Posted September 12, 2014 Share Posted September 12, 2014 Hey guys, I've been pretty busy lately trying to make an overhead game using a tilemap and arcade physics. I'd like the game to be functionally infinite in all directions, à la Minecraft. I came up with a few ideas to make this work and would appreciate some feedback or advice from people that re doing similar concepts. The first solution, to make the game limitless. What I mean by this is to not do anything particular to make it limitless, simply make the camera follow the player, and do not give any bounds.Pros:Trivial to implementCons:Limited by floating point precision, which may even vary by device Another common approach for this is to "move the world, not the player". The benefits of this is that you basically never encounter precision issues, because all the entities you see, including you, are at or near the origin.Pros:Virtually infiniteCons:Very hard to implement (everything has to be converted to local/world space all the timePhysics might not work with the existing systemsThe world might contain a lot of sprites, so moving the player implies moving a lot of sprites, which may not be efficientAn approach I thought of is to create a tilemap larger than the screen. When the player reaches the edge of the screen, the tilemap is shifted to the left, and the player is recentered at the origin. For example, imagine a square 3x3 tilemap and only 1 tile fits on the screen. If the player moves right, we destroy all the left tiles, shift all the tiles left by one, load 3 new tiles on the right, then recenter the player.Pros:Very few tiles loaded at anyone timeSomewhat easy to implementCons:When recentering everything, there will probably be a moment of stutter I'm open to suggestions/comments/ideas for this project/concept Link to comment Share on other sites More sharing options...
JUL Posted September 12, 2014 Share Posted September 12, 2014 What's the context of your game ?I mean, it's occuring in space or on land with various landscapes ? I was thinking about a zone that is fixed, let's say a big rectangle, with some infinite scrolling zone at its borders.The first "escape velocity" game had something like that I think, but I'm not sure. Link to comment Share on other sites More sharing options...
Nepoxx Posted September 12, 2014 Author Share Posted September 12, 2014 "Minecraft viewed from above" describes it pretty well. I'm also interested in the theoretical aspects of it as well Link to comment Share on other sites More sharing options...
gnumaru Posted September 12, 2014 Share Posted September 12, 2014 I found this article which seems interesting: http://0fps.net/2012/01/14/an-analysis-of-minecraft-like-engines/ The author does an analysis on approaches to implementing voxel engines. Even though it is about 3D worlds, you could just “cut out one of the dimensions” and think 2D =) Nepoxx 1 Link to comment Share on other sites More sharing options...
Nepoxx Posted September 15, 2014 Author Share Posted September 15, 2014 Awesome link gnumaru, thanks! The main issue is that I'm not sure how Phaser can help me. If I use a tilemap, I necessarily have to move the player around, and that won't work with an infinite world. So I kinda have to create the tiles myself using sprites and groups, however, at that point, am I better off using pure pixi instead? Link to comment Share on other sites More sharing options...
xerver Posted September 15, 2014 Share Posted September 15, 2014 > If I use a tilemap, I necessarily have to move the player around, and that won't work with an infinite world Technically you move the world, not the player. But you will have to create the tiles yourself and do your own procedural generation. Link to comment Share on other sites More sharing options...
Nepoxx Posted September 15, 2014 Author Share Posted September 15, 2014 > If I use a tilemap, I necessarily have to move the player around, and that won't work with an infinite world Technically you move the world, not the player. But you will have to create the tiles yourself and do your own procedural generation.Well that's exactly what I want to achieve (move the world, not the player), but I can't really move tilemaps around can I? I thought about using tilemap.scroll, but does that work with Physics? and how are the coordinates handled when working with scroll? Link to comment Share on other sites More sharing options...
xerver Posted September 15, 2014 Share Posted September 15, 2014 > but I can't really move tilemaps around can I? That is exactly what you do. That is how it works in phaser right now, if you camera follow a sprite it moves the scroll of the tilemap around beneath the sprite. Link to comment Share on other sites More sharing options...
Nepoxx Posted September 15, 2014 Author Share Posted September 15, 2014 > but I can't really move tilemaps around can I? That is exactly what you do. That is how it works in phaser right now, if you camera follow a sprite it moves the scroll of the tilemap around beneath the sprite.Oh, then this thread is potentially useless. Is there a way to make it "wrap" around? Since my tilemap's size will be limited, if it doesn't wrap around I'd have to have multiple tilemaps to be able to have an infinite world. In this image, the redsquare is the "screen" (what the player sees). When the player moves to tilemap 5, I would move tilemaps 0,3 and 6 to the right, and replace whatever content they had with new tiles. However I don't know if this is at all possible with tilemaps, or advisable. Link to comment Share on other sites More sharing options...
xerver Posted September 15, 2014 Share Posted September 15, 2014 Sure its possible, just need to manage what tilemaps are loaded and that memory yourself. There are no automatic features to do what you want, you just need to track the user and load/unload tilemaps as needed. Think of it like a tilemap where each tile is a tilemap, just manage it yourself. Nepoxx 1 Link to comment Share on other sites More sharing options...
horkoda Posted September 15, 2014 Share Posted September 15, 2014 This example shows how to enable wrap in Phaser 2.1.x. Link to comment Share on other sites More sharing options...
Nepoxx Posted September 23, 2014 Author Share Posted September 23, 2014 This example shows how to enable wrap in Phaser 2.1.x. But it doesn't really wrap like I want it to. I'd like the camera to ALWAYS follow the player around. In that example, the camera doesn't follow the player around near the edges. Something similar to this, but where the camera always follows the player and the wrapping is not noticeable is what I'm looking for. Link to comment Share on other sites More sharing options...
wayfinder Posted September 24, 2014 Share Posted September 24, 2014 Try setting the camera bounds to null! Link to comment Share on other sites More sharing options...
Nepoxx Posted October 7, 2014 Author Share Posted October 7, 2014 Try setting the camera bounds to null! Well that works somewhat, I get the intended behaviour with one major caveat, the world doesn't render outside the bounds. If you look at my picture above, if you are at the right edge of tilemap5, it will not render tilemap3 to the right of it. The behaviour I'm looking for is something like walking on a planet, if you keep going east you'll see your starting point ahead of you. Link to comment Share on other sites More sharing options...
valueerror Posted May 4, 2015 Share Posted May 4, 2015 stumbling across the very same problem.. did you solve it ? if so.. please show us the way to go Link to comment Share on other sites More sharing options...
Nepoxx Posted May 4, 2015 Author Share Posted May 4, 2015 stumbling across the very same problem.. did you solve it ? if so.. please show us the way to go I did not. none of the pre-built solution worked for me (wrapping, camera bounds, etc.) You'll need a custom solution. I tried "moving" the entire world back to the origin when exiting a cell, but there was a noticeable jitter when doing so. I think that too many of Phaser's rely on absolute coordinates instead of relative coordinates, which makes a "the world moves, not the player" solution very hard, if not impossible, to implement. Link to comment Share on other sites More sharing options...
valueerror Posted May 4, 2015 Share Posted May 4, 2015 well i found a solution for my 2 - directional game.. (only east/west) every tilemap has the exact same size.. (200x20 tiles)32 tiles match the cameraview (32*24= 768) that's the width of my camera every tilemap repeats the last 32 tiles from the former tilemap.. that way i can check the playerposition and if the player has reached the last part of the map (the moment where the camera wouldn't follow because the player is at the "worlds end" ) i kick the player.x coordinate back to the beginning of the map - kill the whole map and replace it with the next map.. i also store the current number of the map and if the last map is loaded it will then load the first map again at it's end.. that way i have a working worldwrap implemented it's definitely not perfect and i can see a really small glitch if i'm careful (as if there were 58 normal frames and 2 white frames) i thought i could build on this.. probably load the next map already 100px before that certain point and only change the visibility state.. that way the glitch should be gone..unfortunately i have no idea how you would implement this in a 4 way map or even 8 ways Link to comment Share on other sites More sharing options...
valueerror Posted May 4, 2015 Share Posted May 4, 2015 i tried preloading the map 1000 px before the worldend and then just switch the alpha state BUT id didn't help.. moving everything to preRender() made it a little bit better but the glitch stays.. it is actually not caused by the map change but by the repositioning of the player.. so the best way would still be to have a camera without bounds (so it will scroll forever) and just put the new map at the end of the last map.. but it seems that i can not postion a layer relative to another ? or can i ? newmap.x = oldmap.width; // that would be cool Link to comment Share on other sites More sharing options...
Nepoxx Posted May 4, 2015 Author Share Posted May 4, 2015 i tried preloading the map 1000 px before the worldend and then just switch the alpha state BUT id didn't help.. moving everything to preRender() made it a little bit better but the glitch stays.. it is actually not caused by the map change but by the repositioning of the player.. so the best way would still be to have a camera without bounds (so it will scroll forever) and just put the new map at the end of the last map.. but it seems that i can not postion a layer relative to another ? or can i ? newmap.x = oldmap.width; // that would be coolThe reason why you want to move the world and not the player is that if you remove the camera bounds, your player can reach a point where it's coordinates stop being accurate and becomes jittery. This is due to limited floating point precision and is inevitable. Now, you have to ask yourself how far do you realistically expect a player to reach. If you allow your player to teleport, this is definitely an issue. If your player can fly at insane speeds, again, this can be a issue (it also depends on your scale). However, if your player starts at (0, 0), and doesn't move amazingly fast, you might get away with a non-infinite world. That's what minecraft does. Link to comment Share on other sites More sharing options...
valueerror Posted May 5, 2015 Share Posted May 5, 2015 thx.. but it seems it is not possible to move a tilemap layer.. i managed to move it but it's cropped at the camera-view so its just the first 768 pixel that are moved.. the rest is invisible.. Link to comment Share on other sites More sharing options...
newpdv Posted July 4, 2015 Share Posted July 4, 2015 It describes a method for moving the tilemap: http://www.html5gamedevs.com/topic/13117-how-to-position-multiple-tilemaps/But after moving the physics does not work Link to comment Share on other sites More sharing options...
Recommended Posts