MichaelSinsbeck / platformer

A ninja platformer written in LÖVE
7 stars 0 forks source link

[LE] Map Dimensions #101

Closed Germanunkol closed 10 years ago

Germanunkol commented 10 years ago

I thought about how to resize maps. While the code behind it is very simple (change dimensions and offset everything in the map, then redraw) I would like to avoid popups and extra windows. Also, we'd need widgets for it which will not be used anywhere else - I think it's a waste of time.

Instead, I thought we could go for an "infinite canvas" approach. The idea:

The downside: We either need to store huge arrays in memory or resize them in the background every now and then. I think it would be good to keep a 2d-Array to store the map in memory, which is the size of the current map plus a padding around it - maybe 300 tiles in each direction. Only when the user gets close to this boundary, the map is automatically resized in the background.

michalove commented 10 years ago

I like the infinite canvas idea. The current bounds should be visible to the user. Maybe just by a dashed line and a gray half transparent area outside.

There is one design problem, namely if we have a map that is empty in the top row (or bottom row or left or right column). Then we'd have to place a 'ghost' tile somewhere to mark the map size. I don't know if this will happen, though. We will see.

For the storage: In Lua we can set all empty cells to nil, which results in a "sparse" array. I would believe that this will not cause memory problems. Currently the maps are handled like this.

And for the infiniteness: We can easily have negative indices in the array. This will not be visible to the user. And once we save a map, we can shift everything, so the first index starts at one (or zero).

Germanunkol commented 10 years ago

Ah, thanks for reminding me about the negative indices! I was thinking that the sprite batch can't handle that, but that's wrong, off course... That's perfect! That makes it all so much simpler.

About the empty space at the map's side: That's true, off course. I suggest we draw the map borders as a dotted line as you mentioned (and update them whenever the user places down a tile), but let the user drag them out in all directions if they want to do so.

michalove commented 10 years ago

I replaced the grid drawing. Now it uses an image that is drawn tiled using a quad that is much larger than the image.

That means that right now, it is not visible to the user, where he can draw.

Germanunkol commented 10 years ago

I consider this pretty much done. The method we use right now can, theoretically, scale from -Size-of-integer to +Size-of-integer ... which is way more than enough.