Tiled Map Engine

Thanks for the reply. 

I noticed, what I thought was some strange behavior. I created a scene with two layers, foreground and background. I have two “player” type objects that move in the scene. I added the objects to the scene via: 

map.layer["foreground"]:insert( player )  

I also set the camera focus on one of these with:

map.setCameraFocus( player )  

The object that has camera focus is always in front of objects in the foreground. While the object that does not have the camera focus is in front of some tiles in the foreground layer while behind others. 

I’ll just answer my own question here, and point that I should probably make a layer for these objects and place it in front of the foreground layer if I want them to always be in front. I’m guessing it’s something to do with culling. The as new tiles come in view they are added to the layer and end up on top. 

@soggybag:

You can fix that issue by adding a line of code here:

[lua]

– Ceramic.lua line 495

layer:insert(tile)

tile:toBack() – Add this

[/lua]

Again, as soon as Dusk gets out, all these issues will receive “official” support (as in pushed to the repository, rather than advice to fix it given).

  • Caleb

Thanks again! I’m having a great time with this, Ceramic works really well. 

I had a question about Tiled. I’d like to draw a shape like a star or triangle. I remember reading something in this thread that shapes other than rectangles don’t always work. Either way I’d like to give it a try. The problem I’m having at the moment is, using the line tool in Tiled I can never get the shape to finish. I tried double clicking, pressing escape? 

– Edit –

After a couple tests it seems that shapes other than the rectangle and circle don’t work. I get an error in Ceramic something about reversePolygon not found. 

Another question, is it possible to fill a shape object with a tile pattern? Seems this might be possible with Graphics 2.0? 

The Platformer sample works fine but, there seems to be something missing from the tmx file. If I edit this file and export a new json file I get an error. I isolated it to the playerSpawnPosition. If comment this line there no error. 

player.x, player.y = map.tilesToPixels( map.layer["layer\_1"].playerSpawnPosition )  

I can’t seem to get this sorted out. There is a rectangle on the objects layer named “playerSpawnPosition”.  The following doesn’t work:

map.layer["objects"].playerSpawnPosition  

print( map.layer['objects'] ) -- shows nil  

What am I missing here? In another sample, where I created the map, I created an objects layer name “objects” and map.layer[“objects”] finds this layer. 

If I create a physics object in Tiled, and want to set the values for physics properties like friction and bounce, using the property dialog would the proper form be? 

Name:

physics:friction

Value: 

0.3

This seems to work. While I’m experimenting here I’ll point out that

bodyType, dynamic 

and 

physics:bodyType, dynamic both work. 

Caleb,

Thanks for your answer.  I’m having some problems with my map:

  1. When I enter the property shape in one of my tiles, it is still being drawn as an square physics object.  Here are the points I have entered:

{-16,-16,-12,-16,16,16,0,16,-16,0} 

I tried entering with and without the brackets with no luck…

  1. As my animated player character is running over the ‘floor’ tiles, sometimes it seems as if he is getting stuck… feels like he hits the top edge of the tile and a collision happens.  If I make him jump and move forward a bit, it runs over that tile and hits the next.  Any ideas what could be causing this behavior?

  2. I tested the map on a Kindle Fire and sometimes there is a tile missing, and in some cases I see lines between the tiles that “give away” the tile structure… Is there a work-around for this?

THANKS in advance for all your help!

Is it possible to loop through all of the objects on a layer? Imagine I have created an object layer in Tiled containing many rectangles all named “platform”. I’d like to loop through these in Corona and assign them some properties and what not.

A realated question, the object name field, should this be unique like and id? And what is this mysterious type field in the object properties box? What can that be used for?

Glad you’re enjoying checking out Ceramic :slight_smile:

Now, to respond to your posts…

I had a question about Tiled. I’d like to draw a shape like a star or triangle. I remember reading something in this thread that shapes other than rectangles don’t always work. Either way I’d like to give it a try. The problem I’m having at the moment is, using the line tool in Tiled I can never get the shape to finish. I tried double clicking, pressing escape? 

Draw your shape with each click, then right-click to un-toggle that shape’s drawing. To return to “object selection” mode, click the “Select Objects” button (or press S).

After a couple tests it seems that shapes other than the rectangle and circle don’t work. I get an error in Ceramic something about reversePolygon not found. 

Just found a typo - on Ceramic.lua, line 54, change the name from reversePolygonPolygon to reversePolygon. Don’t know how that got in there :slight_smile:

Another question, is it possible to fill a shape object with a tile pattern? Seems this might be possible with Graphics 2.0?

I believe so. I’m not sure how tiling an image would work in Corona code, but from the top of my head, it seems you could do this in an object’s properties to make a single image (pulled the code from the Corona docs):

fill : !json! {"type" : "image", "filename" : "aquariumbackgroundIPhone.jpg"}

The Platformer sample works fine but, there seems to be something missing from the tmx file. If I edit this file and export a new json file I get an error. I isolated it to the playerSpawnPosition. If comment this line there no error. 

player.x, player.y = map.tilesToPixels( map.layer["layer\_1"].playerSpawnPosition)

I can’t seem to get this sorted out. There is a rectangle on the objects layer named “playerSpawnPosition”.  The following doesn’t work:

map.layer["objects"].playerSpawnPosition print( map.layer['objects'] ) -- shows nil

What am I missing here? In another sample, where I created the map, I created an objects layer name “objects” and map.layer[“objects”] finds this layer. 

Yep, the TMX is missing the playerSpawnPosition (whoops!). If you open the JSON file with Tiled, you should be able to export it as TMX and thus reverse the error.

 

If I create a physics object in Tiled, and want to set the values for physics properties like friction and bounce, using the property dialog would the proper form be? 

Name: physics:friction Value:  0.3

That’s right :slight_smile:

 

Is it possible to loop through all of the objects on a layer? Imagine I have created an object layer in Tiled containing many rectangles all named “platform”. I’d like to loop through these in Corona and assign them some properties and what not.

You can loop through them now with this:

for i = 1, #map.layer["layer"].object do   if map.layer["layer"].object[i].\_name == "platform" then -- Whatever end end

I wouldn’t advise this, though; Dusk has a whole slew of iterators, and you’ll want to use the “official” way:

for object in map.layer["layer"].objects() do -- Every object end for object in map.layer["layer"].nameIs("platform") do -- All objects whose name (set in Tiled) is "platform" end for object in map.layer["layer"].typeIs("myType") do -- All objects whose type (set in Tiled) is "myType" end for object in map.layer["layer"].objTypeIs("rectangle") do -- All objects that are rectangles end

Plus a number of others…

A realated question, the object name field, should this be unique like and id? And what is this mysterious type field in the object properties box? What can that be used for?

The type and name fields in Tiled are both transformed in Ceramic to obj._type and obj._name. These can be used for whatever you want.

Hope this answered your questions :slight_smile:

  • Caleb

Thanks for all the help. I really like Ceramic, can’t wait for the update. I’d love to help you guys out, maybe I can make a couple examples to show some features?

I’m playing around at the moment getting the hang of things. Today I started a Doodle Jump clone. Took a little while figure out the platform mechanic and get things set up through Tiled.

Is there a method to recycle tiles? Imagine you you’ve gotten to the right side of your tile map and want to see the tiles from the left appear, if that makes sense.

Thanks for all of the great info. 

After making the edit above polygon shapes started working. I still couldn’t them to display with a fill.

ceramic.virtualObjectsVisible = true  

This didn’t seem to do anything for me. I didn’t try the image fill. I’m not sure how to add the following via Tiled. 

fill : !json! {"type" : "image", "filename" : "aquariumbackgroundIPhone.jpg"}

I figured out how to loop through all of the objects on my own with a little trial an error, and poring over the sample code. The iterators sound like a great idea, I’m a big fan of iterators. Thanks for pointing out the _name property. 

Here’s what I used to fix offset caused by the differences in Graphics 2.0. 

for i = 1, #map.layer["objects"].object do      -- print( "\>\>\>\>", map.layer["objects"].object[i].rotation )     local obj = map.layer["objects"].object[i]     obj.x = obj.x + obj.width \* 0.5     obj.y = obj.y + obj.height \* 0.5 end   

I tried to reverse the platformer.tmx from platformer.json. It sort of worked but there were some problems. The platforms all disappeared, at least all of the ones drawn as a lines. In the original tmx file these line objects don’t have a name. It seemed that only the named objects were listed in the objects list when the file was reimported. 

There is also a rectangular area of missing tiles. The tiles show in Tiled but are missing in Corona. I suspect there is some corruption. No worries, I think I can recreate this on my own at this point. 

Still having a great time with Ceramic. I was wondering is it possible to animate tiles? Something like designating tiles as Sprites in Tiled, and assigning some properties, like frames, time etc. 

<p>Another question. I’m working on a platformer style game and want to implement coins, or other things that can be picked up along the way. I added these elements to the object layer, and assigned them a collisionType = “sensor”. I have a preCollision handler with something like this: </p>
<div>
<pre class="_prettyXprint">
if event.other.collisionType == “sensor” then
     event.other.isVisible = false
     event.contact.isEnabled = false
end
 </pre>
<p>This works but, it doesn’t quite “feel” right. In effect my coins are static objects that get removed just before they are hit. </p>
<p> </p>
</div>
<p> </p>

I got another Tiled question. I want use Tiled to create a pinball game. Essentially I’d be using Tiled mostly for creating physics shapes. I want to load a single image that will fill the background, and draw on top of this. I see there is an Image layer type but, I can’t figure out how to add an image. 

@Everyone:

Dusk was released in beta to all the volunteers… Just saying this to keep people posted (and because I see some testers don’t appear to have been notified of the PM I started).

@guillopuyol:

  1. Ceramic (and Dusk) loads table properties through JSON; to enable a property to be read as JSON, prefix it with “!json!”. Then, the remaining area of the property must be in JSON notation.

  2. Yes… Box2D has trouble with side-by-side objects, and any other objects catch at the “seams”. To remove this (or at least minimize the effect), reset the player’s velocity each frame (according to if he’s moving left or right).

  3. Currently, you’ll have to disable tile culling to keep the missing tiles from showing up. As for the seams between tiles, this is a very common problem that can be fixed usually with this:

[lua]

display.setDefault(“minTextureFilter”, “nearest”)

display.setDefault(“magTextureFilter”, “nearest”)

[/lua]

I was wondering is it possible to animate tiles? Something like designating tiles as Sprites in Tiled, and assigning some properties, like frames, time etc. 

Not currently. This will arrive as an update once Dusk gets released.

 Another question. I’m working on a platformer style game and want to implement coins, or other things that can be picked up along the way … 
This works but, it doesn’t quite “feel” right. In effect my coins are static objects that get removed just before they are hit.

What about a collision event, rather than preCollision?

[lua]

function coin:collision(event)

  if “began” == event.phase then

    – Etc.

  end

end

[/lua]

I want use Tiled to create a pinball game. Essentially I’d be using Tiled mostly for creating physics shapes. I want to load a single image that will fill the background, and draw on top of this. I see there is an Image layer type but, I can’t figure out how to add an image. 

Add Image Layer -> Layer Properties -> Image :slight_smile:

  • Caleb

Thanks again. Here’s another question. Is it possible to add new tiles to a layer via Lua? For example if a game event occurs I want to add a new tile. 

Also, is it possible to pole a tile or object image and find it’s frame number and the tile sheet it comes from? I’d like to make a tile map and assign properties programmatically without having to set every property inside of Tiled. This could save a lot of time where all tiles with the same image would have the same props. 

Here’s a Tiled question, when placing objects is there an option to snap them to the tile grid? 

And another question. Is it possible to determine what type of tile is at a location? Really I’d like to fine the tile under a game object, imagine the player moving over the map and apply terrain effects based on the tile under the player. I’m guessing it might be possible to find a tile from an x, y position, from there it might be possible to get the frame number or other feature of a tile. Ideally I’d like to do this without having to assign properties to each tile in Tiled.

I suppose the last couple questions are really asking if it possible to loop through Tiled data and get the frame number for any layer type.

I was reading your docs on Github. Thanks again! This explained most of the questions I had earlier. 

The docs mention scaling a layer by setting the layer property: layerScale. I tried this and it didn’t seem to work. I also tried: layer:layerScale.