dynamic map creation

I was just wondering if there’s a way to create a map dynamicly.

Say, endless map (for endless runner games :wink: ) which you create dynamicly…

Is it possible?

Sorry if this was covered before. Can’t find such things on the forum.

Well, it is possible. At some point in a tile engine you have a method or table where you look up the tile for a particular coordinate, and that could be a function, so you could calculate it on the fly. Problem is speed, you might have to cache the tiles. What actually do you want to do ?

You can dynamically create a map of a fixed size by creating a blank map in Tiled of the desired size, adding your tilesets to the map file as usual, and placing one tile from each set in the empty map, in the top left corner for example. This will create the basic map structure for MTE to load. You can then programmatically fill the map with any data you want.

For an endless runner you would simply set the map to wrap horizontally by calling mte.toggleWorldWrapX(true) before loading the map. You could then change the map data ahead of or behind the player, just beyond the camera view, however you like.

Speed isn’t an issue unless you’re updating many hundreds of tiles at a time, because tiles outside of the camera view are not rendered objects; they’re just data. For example, the following code retrieves the map data and changes the tile ID of location 1,1 to 3:

local map = mte.getMap() map.layers[1].world[1][1] = 3

That is the fastest method of altering the map data. If location 1,1 is already onscreen, however, the tile object will not update until the location moves offscreen and back. You can alter onscreen tiles and the map data simultaneously using mte.updateTile()

mte.updateTile({locX = 1, locY = 1, layer = 1, tile = 3})

@dyson122

thanks for help. the wraped layer idea sounds promising.

is it ok if I just set wrapX param in layer preferences in Tiled?

how do i set tile on map position. is there an method/function in the current API?

@paulscottrobcon

actually I work on side scroll shooter, no the runner game (but who nows :wink: )

You’ll want to set wrapX in the map properties. If you only set one of the layers to wrap then only that layer will wrap. Most maps will have two layers- one for the tiles and one for sprites- if not more.

Check my previous post for API call examples. I was hoping to make the edit before you read the post, but I guess I was too slow :stuck_out_tongue:

thanks. that’s exactly what i need.

great customer support :slight_smile:

Well, it is possible. At some point in a tile engine you have a method or table where you look up the tile for a particular coordinate, and that could be a function, so you could calculate it on the fly. Problem is speed, you might have to cache the tiles. What actually do you want to do ?

You can dynamically create a map of a fixed size by creating a blank map in Tiled of the desired size, adding your tilesets to the map file as usual, and placing one tile from each set in the empty map, in the top left corner for example. This will create the basic map structure for MTE to load. You can then programmatically fill the map with any data you want.

For an endless runner you would simply set the map to wrap horizontally by calling mte.toggleWorldWrapX(true) before loading the map. You could then change the map data ahead of or behind the player, just beyond the camera view, however you like.

Speed isn’t an issue unless you’re updating many hundreds of tiles at a time, because tiles outside of the camera view are not rendered objects; they’re just data. For example, the following code retrieves the map data and changes the tile ID of location 1,1 to 3:

local map = mte.getMap() map.layers[1].world[1][1] = 3

That is the fastest method of altering the map data. If location 1,1 is already onscreen, however, the tile object will not update until the location moves offscreen and back. You can alter onscreen tiles and the map data simultaneously using mte.updateTile()

mte.updateTile({locX = 1, locY = 1, layer = 1, tile = 3})

@dyson122

thanks for help. the wraped layer idea sounds promising.

is it ok if I just set wrapX param in layer preferences in Tiled?

how do i set tile on map position. is there an method/function in the current API?

@paulscottrobcon

actually I work on side scroll shooter, no the runner game (but who nows :wink: )

You’ll want to set wrapX in the map properties. If you only set one of the layers to wrap then only that layer will wrap. Most maps will have two layers- one for the tiles and one for sprites- if not more.

Check my previous post for API call examples. I was hoping to make the edit before you read the post, but I guess I was too slow :stuck_out_tongue:

thanks. that’s exactly what i need.

great customer support :slight_smile: