Tiled Map Engine

@Curt

I didn’t know that the points needed to be clockwise… That would make sense. I found this code on stack overflow to order points in that way…

function appSortPointsClockwise(points)  
 local centerPoint = appGetCenterPointOfPoints(points)  
 app.pointsCenterPoint = centerPoint  
 table.sort(points, appGetIsLess)  
 return points  
end  
  
function appGetIsLess(a, b)  
 local center = app.pointsCenterPoint  
  
 if a.x \>= 0 and b.x \< 0 then return true  
 elseif a.x == 0 and b.x == 0 then return a.y \> b.y  
 end  
  
 local det = (a.x - center.x) \* (b.y - center.y) - (b.x - center.x) \* (a.y - center.y)  
 if det \< 0 then return true  
 elseif det \> 0 then return false  
 end  
  
 local d1 = (a.x - center.x) \* (a.x - center.x) + (a.y - center.y) \* (a.y - center.y)  
 local d2 = (b.x - center.x) \* (b.x - center.x) + (b.y - center.y) \* (b.y - center.y)  
 return d1 \> d2  
end  
  
function appGetCenterPointOfPoints(points)  
 local pointsSum = {x = 0, y = 0}  
 for i = 1, #points do pointsSum.x = pointsSum.x + points[i].x; pointsSum.y = pointsSum.y + points[i].y end  
 return {x = pointsSum.x / #points, y = pointsSum.y / #points}  
end  

I will try and add that in this week… [import]uid: 51498 topic_id: 35538 reply_id: 144882[/import]

Oh, and BTW (I know this is 3 posts right in a row) I’m in love with the names, and I like the idea of breaking out the different renders to keep the overall project from getting too complicated. Here’s how I see it working…

require ("ceramic") -- object physics and rendering to display object  
require ("quartz") -- rendering/culling engine for large maps  
require ("marble") -- some cool other feature, maybe random map generation  
etc  
etc  

all of these libraries would require the tiled.lua core that could share the loading/savinging/ect. [import]uid: 51498 topic_id: 35538 reply_id: 144884[/import]

Awesome, glad that was the case, I can’t wait to use it, though unfortunately I have 3 midterm tests this week, a quiz, and a lab, so I’m a bit full. So question, does CoronaTiled currently only load in object layers or does it load in tiles as well at the moment? I know you guys plan to eventually make it into two separate parts, but just asking for the current version.

Thanks a ton guys, your work is amazing, once the word gets out I’m sure a ton of people will be using it. [import]uid: 215209 topic_id: 35538 reply_id: 145019[/import]

@no2games:
Should have said potentially extremely fast :slight_smile:

From working a bit more on it, I think I’ll keep that for now. I’m attempting a new method of culling, just to see which is the easiest/cleanest/fastest. Now I’m going to try removing and adding tiles offscreen and onscreen. So I’ll see which is fastest.

C [import]uid: 147322 topic_id: 35538 reply_id: 145060[/import]

FYI: I pushed some bug fixes out this morning…

@ Caleb

Potential performance vs. actual performance :slight_smile: That gets me every time.

@cjc83486

Yes, the code in the link above does all this…

  • JSON/LUA exported map files
  • Multiple Tile Layers
  • Multiple Tilesets
  • Margins and spacing
  • Uses Corona Image Maps and Image Map groups if you limit yourself to a single tileset image
  • Object types (regular, polygon, line)
  • Image Objects
  • Physics and display object properties
  • Image Layers

It’s pretty much good to go to build a full game. In fact, I was going build a quick clone of a Labyrinth-style game using Ceramic/Tiled as an example. I figure it would be about 150 lines of code tops. [import]uid: 51498 topic_id: 35538 reply_id: 145068[/import]

no2games:

Hey I’ve been looking over your code and trying to incorporate it into my game, however, it seems that if you try to use more than one tile set it doesn’t work? I don’t know if you meant to make it that way or if it is a bug?

-Curt [import]uid: 215209 topic_id: 35538 reply_id: 145485[/import]

It should load as many tilesets as you put in, so it’s probably a bug. (However, using a single tile sheet makes for faster map rendering…)

Can you make a map that breaks and post it out on a dropbox link?

[import]uid: 51498 topic_id: 35538 reply_id: 145553[/import]

I’ve worked on Quartz a bit more, and, instead of automatic culling, it now has a more customizable memory saving method. I’m not quite finished with it, so I’ll probably post it up tomorrow. Here’s a teaser, though:
[lua]
function quartz.render(mapFile, x1, y1, x2, y2)
[/lua]

C [import]uid: 147322 topic_id: 35538 reply_id: 145554[/import]

@Curt,

I added a second tile layer to the demo.tmx file and it seems to be working fine, but I don’t know if i fixed some other bug that made it work, so I pushed a 0.3 release out to GitHub.

So re-grab the files and see if that works. If it doesn’t send me your map and I will debug it. One other thing, I try to strip all directory info from a tilemap, so the .json file and the .png file both need to be in the root directory for now. Also, the tilemap image files can’t have any other slashes, hyphens or periods in them.

@Caleb,

Sounds good. So are you using the Map Loading function that I’m using, or are you doing your own? I was thinking about breaking out the Map Data+Physics+Properties into a separate call so you passed the structure to the renderer. That way for small maps you could call Ceramic as the renderer and for large maps Quartz.

I still need to spend a few hours renaming everything to Ceramic and making a screencast.

By the way, I found a good and complicated TiledMap with 8 layers and plenty of tiles here…

https://github.com/silveira/openpixels/tree/master/examples/tiled

This renders at about 25FPS on my iPhone 5, so it would be a good benchmark for you renderer. [import]uid: 51498 topic_id: 35538 reply_id: 145557[/import]

It seems putting the .png files in the root directory was the solution. I had them in a subfolder before. Can they not be in a subfolder when you publish it with apple, or is it just something you currently have on the back burners?

Thanks a lot for the help though.

**Edit**

I got the object layer to work, however I found a bug when using .lua files and not .json, it seems the ellipse renders as a box and not an ellipse? Weird, I didn’t look into it too much and just exported my file as a .json instead. [import]uid: 215209 topic_id: 35538 reply_id: 145624[/import]

@No2Games:
Quartz doesn’t do automatic culling - yet. Right now it loads “chunks” of the map, which can be added to or removed from the entire thing. Here’s how you use Quartz:

[lua]
local thisMap=quartz.render(“thisMap.json”, 1, 1, 32, 24) --> Only render a “chunk” specified, if no dimensions it renders the whole thing
thisMap.draw(32, 24, 33, 25) --> Add to the drawn “chunk”
thisMap.erase(32, 24, 33, 25) --> Remove from the “chunk”
[/lua]

I believe culling shouldn’t be too hard… some sort of a function that adds to one side and erases another when it’s moved. The problem is, I’ve not figured it out. I’ll keep at it, though :slight_smile:

[EDIT]: I’ve already found a bug in the “draw” and “erase” functions… So it’s not quite finished, it would appear :frowning:
[EDIT 2]: I’m just going to take it down, for now. I’ve found quite a lot of bugs - just after I made it public. So I’ll work on it a bit more.

C [import]uid: 147322 topic_id: 35538 reply_id: 145636[/import]

I’ve still been working on this off and on… I did pull the Physics/Properties code out of GridMap and added to Tiled, but it wasn’t working like I wanted. But, I had a big break though today and bang out a lot of stuff that was just kinda working:

* Set properties & physics from Tiled (thanks to Caleb + GridMap)
* Image Layers
* Object Layers (except for tile objects)
* Physics on object layers with generated bounding shapes (first 8 points)

I still need to clean up some stuff before releasing it into the wild… but it’s looking pretty good.

corona tiled 1

corona tiled 2

[import]uid: 51498 topic_id: 35538 reply_id: 144563[/import]

Wow - looks great!

I’ve also been working on it… Not getting such good results. I’ve been trying (and mostly failing) to get a culling system up.

Which makes me think that we should make a tiled image loader separate from a tiled level builder. I suppose it could just use object layers for physics, and then add it all into the tiled image loader.

Anyways, any ideas on what to name it?

C [import]uid: 147322 topic_id: 35538 reply_id: 144571[/import]

Yes, at some point we should break out the loader/parser from the rendering engine or have different kinds of calls to load maps…

I for sure want to add some more parameters to the load call so you can get to just a portion of the map. that should be enough culling for 99% of the people out there…

function tiledMap:load( mapFile, tileTop, tileBottom, tileWidth, tileHeight )  

Also, one of the issues right now is it’s really hard to set properties of an individual tile in (x,y) space or set an individual objects properties when a object layer has it’s properties set–all these cases tend to overwrite each other.

I think I need some sort of table merge that has a preference setting for which table overwrites the others values.

As far as names go, I’m happy with something simple and straightforward. CoronaTiled is what the GitHub prodject is named, but I’m open to suggestions. :slight_smile: [import]uid: 51498 topic_id: 35538 reply_id: 144577[/import]

Wow, this is nice! Few questions:

Are you using Gridmap, or the one you made previously?
*If the latter, I think you guys should settle on one or the other so you guys don’t overlap on problem solving. :slight_smile:

For the objects that are polygons, it looks like you can use 8 points, in which they can be non-convex as well… is this correct? For the polygon shapes, it looks like there is no middle to the object, do objects sometimes accidently go through these since it has no thickness?

I was talking to Caleb about this before on his gridmap forum, but I’m guessing you’re not subscribed to that Topic… do you think you could have this ready to be used by March 15th? I know it’s only 2 weeks but it seems you are pretty far on it, and that’s when my spring break is. I’ve got a full school load so it’s really the only time I have to put a large amount of effort into my project, so if you could that’d be amazing.

Thanks a lot to the both of you, literally are lifesavors (I wouldn’t have known how to create my game without your projects).

-Curt [import]uid: 215209 topic_id: 35538 reply_id: 144600[/import]

Curt,

This is a combination of GridMap + CoronaTiled, so hopefully you get the best of both. Fast ImageSheet based multi-layer maps and object layers (my CoronaTiled) AND the ability to set Physics and other properties from the Tiled property editor (Caleb’s Gridmap) with some bug fixes and other fun stuff tossed in for good measure.

I think your right, we need to pick a new name and start this as a fresh project so it isn’t confused with all the other projects out there.

Corona’s limit on a physics body is 8 points, and non-convex–I don’t check for either, I just pass the first 8 points and hope for the best.

Things like this are NEVER finished, especially since Tiled supports so many options, but I will post the code so far and an example project/tmx map on GitHub either tomorrow or early next week.

Hopefully a few people can try it out and post some bugs and we can all have something stable by 3/15.

I see few “showstoppers” that I would want to have before we call it a 1.0 version:

* Image layer properties (Stretch to fill map, Tile to fill map)
* A display.newRect() as a map background (solid, gradient)
* Inherited properties at the Map -> Layer -> Individual Tiles/Objects
* Tile objects (player start, power ups, etc)
* Chunking or culling maps
* A few demo projects and maps (Platformer, RPG, Big Map, etc.)
* Documentation, or at least a screencast or two

Anything I’m forgetting? [import]uid: 51498 topic_id: 35538 reply_id: 144611[/import]

I’ve got a name idea - Quartz Tile Engine. That way, if we ever separate the tile renderer and the level builder, we can use rock/mineral names for it to go with the theme. It also sounds pretty cool…

Let me know if that sounds good. That’s all I posted to say - I’ll be back (hopefully) in the morning :slight_smile:

C [import]uid: 147322 topic_id: 35538 reply_id: 144614[/import]

No2games and Caleb,

Yeah that sounds awesome, I don’t mind if a few bugs come up, I’d be happy to test run most of the versions and updates. The game I’m currently making is a RPG, so if you have someone that is making a Platformer, we should have 90% of users covered testing wise.

As far as the design go, I like the idea of making physics objects mainly for the object layer. For most RPG users, I’m unsure if they will benefit too much from tile physics layers over object physics layers. Anyway, this is how I imagine using it:

–Use tile-LAYERS for fore-ground and back-ground layers. *Currently what I’m doing is putting “ground” in the name of the Tiled layers I am having my player walk on. I use a search function for each layer to check for the substring “ground” and put it underneath my character, the rest are set to above.

–Use an Object-PHYSICS-LAYER for houses, trees, fences, etc.
*here you just set the Object physics layer invisible with .isVisible=false These objects don’t really need to be distinguished and can be treated as a layer, since all you need to do is bump into them.

–Use INDIVIDUAL-PHYSICS-Objects for power ups/items/NPC characters
*How I do power-ups currently is use a pre-collision event handler and remove the object before I collide with it. Really all you guys should have to do is to make it so users can access individual OBJECTS. Currently you can set properties on individual objects, so really all people would need to do is have a ‘type’ or ‘name’ property where they can code “Make all objects of type “potionItem” do this…” Basically that functionality is already in there.

–Use Object LAYERS for spawn areas
*Basically you can randomly spawn enemies or items within the bounds of layers of type “spawnArea”. Same thing with a Player start position object. This way making maps is really fast and there aren’t enemies wedged in trees and such.

–Use INDIVIDUAL-Objects for things such as doors and NPC (non-player characters) talking radiuses.
*I’m not sure if I need to use these as physics objects, rather I may just make it when my player is colliding or within a certain distance with these objects to bring up a “talk” or “open door” button once pressed you change map or display talking text.

Well there is how I plan to use it. As you can see, really all you guys have to do is make it so people can add tile layers for background, physic-object-layers for the general static collision (people can make multiple if they want to add character jump features… etc.), and individual physics objects and objects. The rest the user should be able to figure out because there are way too many options that a game designer will want. (possibly the only other thing people could want is physics tile layers and individual physics tiles.

Good luck and thanks a bunch,
-Curt [import]uid: 215209 topic_id: 35538 reply_id: 144630[/import]

Okay, I cleaned up everything this morning and added imageObjects as an object type… These are very cool, because they don’t snap to the grid but use the same images as a tile set, so they are perfect for a layer of interaction enabled tiles scattered about a level.

Caleb and Curt, here’s a direct download from gitHub…

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

Take a look at the TMX file as well for how the layer properties are set up. Right now you go into a layer’s properties and simply add “physics:enabled”=“true” and you get a static body. Add “objects:bodyType”=“dynamic” and they are affected by gravity.

Here are the big issues:

  1. You can’t set a single object or tiles properties–only at the Layer level. This needs to change for this to really be, but I don’t want them to completely overwrite each other. So you could set “objects:bodyType”=“dynamic” at the layer level and “angle”=“45” at the object level and both sets of properties should affect the object.

  2. Polygons and Polylines don’t work consistently. I’m new to Box2d, so I don’t know why. Make some triangles (which should never be invalid) and 80% of them work, but a few act like they aren’t even there. Rects, Circles and Lines work 100% of the time

I love the idea of naming the components out of materials that physical tiles are made out of. There’s Porcelain, Marble, Glass, Quartz, Ceramic, etc. I personally would vote for Ceramic because it begins with a “C” like Corona.

[import]uid: 51498 topic_id: 35538 reply_id: 144680[/import]

Pushed a new commit that takes care of #1 in the msg above. Now you can go into an single object and set its properties. The “physics:” prefix doesn’t work, but “bodyType”, “rotation”, etc. all do.

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

Now if I can only figure out #2

This totally makes me want to build a physics based platformer.
[import]uid: 51498 topic_id: 35538 reply_id: 144693[/import]