Tiled Map Engine

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:

@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.

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

Ok, so I’ve been working on the meld, and I’m doing pretty good. So far I’ve finished…

  • Rendering the tiles of a map with Quartz

  • Image layers with Quartz

  • Creating the object layers with Ceramic (your library)

  • Basic physics with Ceramic

I still have to do custom physics, though. I’m creating maps with a .load() function and then giving the user control of rendering and adding physics, instead of doing all that initially.

C

@Caleb,

Sounds good. 

I was thinking about starting to split this stuff up into the individual components like loadData(), renderMap(), etc so we can get ready to name the renders (Ceramic, Quartz, etc.)

Is that what you are working on now? I see it working something like this…

[lua]

mapData = tiled:load(“map.json”)

mapStatic = tiled:ceramic(mapData)

mapDynamic = tiled:quartz(mapData,x,y,w,h)

spawnPoint = tiled:findObject(mapData, “spawnPoint”)

[/lua]

After looking at it, I think it might be a bit much (or confusing) to name the renders individually. Maybe we should just pick one name–either Ceramic or Quartz and do the naming like this…

[lua]

mapData = ceramic:load(“map.json”)

mapStatic = ceramic:render(mapData)

mapDynamic = ceramic:draw(mapData,x,y,w,h)

spawnPoint = ceramic:findObject(mapData, “spawnPoint”)

[/lua]

I don’t know, maybe either looks fine… Any opinions?

Idk, the first doesn’t look any worse than the second…  Maybe you could use Tiled:render for ‘quartz’ and Tiled:construct for ‘ceramic’ if you decide Tiled:ceramic/Tiled:quartz is too confusing.  Anyway, hopefully I should be able to test this all out after next week, I have 3 tests in a row so I’ll be pretty bogged down for a while.  As Mike said, thanks for all your work Caleb, I can’t wait to see it all come together!  You guys have really made something great here, definitely a hidden gem as of now.

@Michael-

Awesome, haha I had actually programmed in my own cruddy version of the find object function.  Now I don’t have to worry about reprogramming it back in when downloading the merged project!

I’ve got it working like this:

[lua]

local myMap=CoronaTiled.load(“demo.json”)

myMap.draw([layer], x1,y1, x2,y2)

–myMap.drawAll()

–myMap.erase([layer], x1,y1, x2,y2)

–myMap.eraseAll([layer])

myMap.tilePhysics([layer]) – Updates tile physics for the map, or for a single layer; physics properties are added via Tiled

myMap.objPhysics([layer]) – Updates obj physics for the map, or for a single layer; physics properties are added via Tiled

[/lua]

And then I have a new type of object - “listener” - that you create by making a 0x0 rectangle in Tiled, giving it a “listener” attribute, and loading the map. Then you can do things like this:

[lua]

–You have a “listener” object with “listener” attribute == “playerSpawned”

local function spawnPlayer(event)

  --Values for the event include “event.time”, “event.x”, “event.y”, “event.name” and I’ll probably add any properties the user adds in Tiled

  --spawn player at event.x,event.y

end

Runtime:addEventListener(“playerSpawned”, spawnPlayer)

myMap.executeListener(“playerSpawned”)

–myMap.executeListeners() – Executes any listeners you’ve created

[/lua]

Sound good?

C

Sure… I’m not trying to force any particular methodology, but I am planning on splitting the load() from the render() function.
 
[lua]
local myMapData=tiled.load(“demo.json”)
local myMap=tiled.render(myMapData)
[/lua]

Here’s why. In my current project I’m using Tiled to layout positions of enemies and imageObjects in the x,y space of the screen, but I’m not using the tileLayers, so I’d like to get at that data without rendering a map.

This also future-looking as Tiled will support image scaling and rotation in an upcoming release, so you could use Tiled to build your game menus or “Limbo” style levels out of placed images.

https://github.com/bjorn/tiled/issues/396

The load thingy that I’m doing is simply loading the map - not rendering or drawing or physics or anything. Then you use the .draw to render some of it, or the .drawAll to render all of it, or .tilePhysics to update tile physics.

So that’s about the same as what you’re doing, only it does it all internally.

C

No worries, I just didn’t want to reinvent the wheel if you were doing it… Also, I’m not looking forward to merging this all together :)  

You should really spend a few hours getting to know gitHub… It makes merging code so much easier.

I’m working on merging it… Slowly but steadily.

I’ll check GitHub out again, maybe I’ll figure it out :smiley:

C

Keeping an eye on the developments here - but just wanted to chime in to emphasise using GitHub or some other form of collaborative system. This would certainly eradicate any potential hiccups, and also make the whole process a lot more efficient. On my first project I tried collaborating with other devs manually and after a short time it became a nightmare trying to merge code, doing the same bits, etc… 

@SegaBoy

Agreed. The gitHub project is here…

https://github.com/superqix/CoronaTiled

…and I plan on continuing to keep it updated even if code needs to be merged outside of gitHub. But it’s not as powerful unless people put issues there, fork and add pull requests.

I’m guilty of that as well, in fact I’m going to add my bug list to the issues right now.

Pushed a few small update this morning.

“Image Objects” now keep a copy of the image they represent in the MapData. It’s hard to explain, but Tiled is going to support arbitrary images that you can place in map space. So basically it is evolving to be a level editor as well as a tile editor. (In fact, the daily builds already support image rotation…) So to prepare for this an Imgage Object now has it’s own image property that includes the corona display object. Confused yet?

Also, tiledMap:findObject() now returns an array of objects so you can find all the objects that match a name. So you can do something like this…

[lua]local found = tiled:findObject(“findme”,map.data)
for i = 1, #found do
found[i].image:setLinearVelocity( 0, 16 )
group:insert(found[i].image)
end[/lua]

In the above example we are finding all the image objects named “findme” and adding them to a display group called “group”

One last thing, you can now set the collisonBits and maskBits of an object or in the case below a whole layer of objects.

Enjoy…

This looks really cool but I’m missing something about the physics.  Is there an option to draw a polygon physics shape around a tile and place it in Tiled?  Can you tie a Polyline shape in Tiled to a tile on an object layer?  Like in the demo scene that comes with the code, if you were to put a non-square tile on the boxes layer, how would you draw the physics shape for it?

Thanks…

Hey Guys,

Since it’s April, and we’ve all been MIA for a long time, I thought I’d post to get us all thinking about Corona Tiled again.

As far as the tile renderer that Caleb is working on, it should be fairly easy to set up a culling system using the draw and erase functions, or using no2games method.  With the latter, you’d have a slightly faster culling system: instead of removing display objects and adding new ones, you’d move display objects to the other side and change the image.  Either method will be much faster than loading the whole map.  

After that is done, all that’s really left is to merge the two tile engines into one so that the user can finally have the best of both in one. This will take you guys having to decide on which little things you want to keep from each, but it needs to get done.

Thanks for both of your guys’ work.  I’m not sure I could have done my game without you two, or at least with a free tiling engine.  When these two things are done I feel like it should cover 90% of peoples’ needs and shouldn’t worry about updating the engine as much.