Tiled Map Engine

Right now you would have to set a custom tile type and loop through the map data to set a tiles physics shape to something custom. If its just one or two custom tiles you could draw them as a vector shape.

Really what I should do is support the basic platformer shapes like slopes, ladders, one way platforms, etc. That way you can set a tiles property to “slopeRight” and it would just get the right shape at the scale of the tile.

Here’s the types of tiles a basic platformer should support …
https://github.com/otternq/GamesVirtualEnvironmentsWeb/diff_blob/91899a76c9f0c31e2d263751f41504853f8b4a1f/src/games/homework1/data/area01_tileset/metatiles32x32.png?raw=true

I’m pushing some updates soon, maybe I will implement slope physics in the next release.

Oh, no2games youre on!

How hard do you think it is going to be to merge both of your guys’ engines?  I mean, I could use Caleb’s draw and erase functions to make my own culling system right now, but it seems silly until they are both combined.

Thanks again guys!

I’ve actually been melding them for some time - I should be finished in a day or two.

C

@cjc

Yeah. It’s been a busy few weeks with the GDC, but I have been working on updates that just haven’t been pushed to GitHub yet.

  1. Now you can load just a portion of the map by calling a top, left, width and height tile. This is the basis of a culling engine, because these loads can happen super fast if you are only calling a few tiles.

  2. Started TMX map support.

  3. Physics updates and fixes. Plus I will probably implement slopes like we’re mentioned in the last post. Should be easy to do.

I just need a full day at home to get them organized and push them out. I’m trying to do a top down RPG with some physics, so most of what I’m dropping in will focus on what a Zelda-like game would need.

I have a little shooter project I’m working on first, so it may be a while before CoronaTiled gets “complete” but I agree this is plenty for most people’s needs. Plus it’s open, so I expect others to add what they need for their particular games.

Good stuff! Look forward to seeing it Caleb.

Awesome guys!  Thanks for the update,  I’m hoping to eventually show you guys what i’ve been working on but I want to make sure I’m a good way into it first.  Happy coding!

@JohnPaul Here’s what I’m thinking of…
 
slope_example.png
 
So now you can edit a tile’s properties as part of the tileset. So if you had a glass tile and you wanted it to be at a 50% alpha you could add that property to the tile in the set, and then every time you place that tile it gets the alpha value set.
 
With that I’m adding a “shape” option that will allow for sub-shapes beyond a square tile. I’m thinking slopes could be ne/nw/se/sw and walls could be top/bottom/left/right. If you wanted to go crazy, you could add corner pieces like in the tileset you see here.
 
So adding a custom shape would just require going into Tiled.lua and adding a new shape beyond the default ones…
 
[lua]
– set Physics properties

if layerGroup.physicsData.enabled==true then

local points

if tile.shape == “nw” then

 points = {0,0,tileWidth,0,0,tileHeight)

elseif tile.shape == “ne” then

points = {tileWidth,0,tileWidth,tileHeight,0,0)                                        

elseif

(and so on…)

end

physics.addBody(tile, “static”, layerGroup.physicsData, shape=points)

end

[/lua]
 
Again, I’m trying to get this update out in a few days

Excellent. I think that will work nicely. Would it make sense to be able to define the shape points in the editor and assign it to the tile in the property editor for odd shapes instead of putting them in the code? Something like if you set the shape property to [{0,0}, {0,0}, {0,0}, {0,0}].

I never think the Tiled editor is a good place to put in data, but you are probably right. :slight_smile:

addBody() looks for points like this x1,y1,x2,y2,…xn,yn, so I could just let you set the shape like this 

[lua]

shape = -20,-10, 20,-10, 20,10, -20,10

[/lua]

and just pass it to the addBody() call. That would be a piece of cake.

That was way easy… It’s working to set the “shape” property of an tile with comma separated x,y values to define the shape of just that tile. So really, you could go crazy defining slopes, ramps, whatever.

So here’s what it looks like…

So you right click on a tile, select properties, and add a shape. Pretty simple…

I will sync this update to GitHub shortly…

Alright, the 0.4 version is up on GitHub…

https://github.com/superqix/CoronaTiled/archive/master.zip

So, this now supports loading a portion of the map like this…

[lua]map = tiledMap:load( mapFile, chunkTop, chunkLeft, chunkWidth, chunkHeight)[/lua]

…and you can set a tile’s properties from the tileset, including the Box2D shape.

Please submit bugs! I’ve already found a few that I need to bang out, and this new stuff is very untested.

I just stumbled upon this.  What an epic post.  I was actually looking for something like this about a month ago! I can’t believe someone from the community made it :slight_smile: thank you so much @no2games

Awesome!!!  I’ll play around with it and try to contribute :slight_smile:

An 0.5 Update is now live that fixes a bug in Objects being lower than they should have been. Also starting support for Sprites as ImageObjects and/or Tiles. Right now you can set the Corona sequenceData for an ObjectLayer and any image object will become a sprite…

An example is in the demo.tmx

@no2games: I was playing with creating the simplest of platform game earlier and I came up with a question. I created a platform/ground in Tiled, setup it’s physics and then I wanted to set a spawn point for my movable character. Here is where I’m not sure how you envision this working. If I put a spawn point marking tile/object on a layer, how am I supposed to find it and its rendered position on the screen? I could see you could loop through the display objects returned by your library and find it based on a property set on the tile but is this how you think this should work? Or should their be a find function in the library? I’m not asking for you to do more coding, I don’t mind doing it and contributing, I just don’t know if this is the way you were thinking this should be used.

@No2Games:

As much as I hate to say it, you might want to start melding them. I’ve got a personal project that’s taking up most of my coding time, and I really don’t want this just to go downhill on account of me. I work on the melding here and there, but if you want it to be actively worked on, you might want to do it.

I am floored that this project has gone this far, and will be willing to do upkeep (or melding still, if you don’t want to do it). As of today, I’m still melding them - if you’re willing to start working on it, though, I’ll stop.

C :slight_smile:

Just wanted to offer some enthusiasm on this - it’s great to see community led, open source projects filling the gaps of Corona. I’m viewing the project and hopefully might be able to offer some input, but feel that what I’ve seen so far is already flying over my head. Without wanting to interfere, what was the breakdown of tasks - as far as I can see it’s only no2Games and Caleb working on it so far???

Yep - Me and No2Games are really the only makers.

I’ve done some rendering code work and created Gridmap (which was one of the two basises for this project), and he’s done everything else (porting Gridmap + Tiled.lua code together, object layers, image layers, physics, etc.). This project couldn’t have even gotten off the ground without No2Games :slight_smile:

By the way - that post above is not a resignation. I still want to be an active maker/creator/editor. I really enjoy this open-source communication and collaborative work :slight_smile:

C

I didn’t setup anything specific for that, but all the map data gets passed back in a mapData table like this…

[lua]map = tiledMap:load(“demo.json”)

print(map.mapData) – table that contains all the data of the map

[/lua]

So if you know the number of your object layer you can loop thru all the objects and set up anything you want based on a custom property. For example, if you added a custom property to an object called name=spawn, you could do this…

[lua]

for i=1, #map.mapData.layers[myObjectLayer].objects do

  if map.mapData.layers[layers].objects[i].name = “spawn” then

    spawn.x = map.mapData.layers[layers].objects[i].x

    spawn.y = map.mapData.layers[layers].objects[i].y

  end

end

[/lua]

I agree through, some helper functions like “findObjectByName()” could make this a little easier to deal with… Feel free to fork the GitHub and add what you want. Our post some code here and I will add it in…

All,

I’m very glad that this project is getting some recognition and people are digging it. First, I want to thank Caleb P, because most of the awesomeness of this project comes from setting custom properties in Tiled, and that was all his code and idea.

Michael Wilson

NO2 Games

@jpcoder
 
Okay, here’s a little update that makes finding objects pretty easy… No custom anything, just set the Name property for an object in Tiled and then you can find it by calling this. Only works for Objects…
 
[lua]
 
function tiledMap:findObject(name,mapData)
    local mapLayers = #mapData.layers; print( “layers”, mapLayers)
    local object
    for layers=1, mapLayers do 
        if mapData.layers[layers].type==“objectgroup” then – search Object layer        
            for i=1, #mapData.layers[layers].objects do
                if mapData.layers[layers].objects[i].name == name then
                    object = copyTable(mapData.layers[layers].objects[i])
                end
            end
        end
    end
    return object
end
[/lua]
 
…and you call it like this…
 
[lua]
spawnPoint = tiledMap:findObject(“spawnPoint”,map.data)
print ("Spawn at ", spawnPoint.x, spawnPoint.y)
[/lua]
 
The example and update are live on GitHub…
 
https://github.com/superqix/CoronaTiled/archive/master.zip