Tiled Map Engine

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. 

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.

I have simple side scrolling game setup. The camera follows the player. This centers the camera on the player. Is it possible to set an offset to position the camera view in front of the player? 

I didn’t see this in the docs, so I’m assuming it’s not a feature (yet…). I’m thinking of two systems to implement this. 

a) create a dummy object that always sits in front of the player object. I was thinking of using an empty group, and setting it’s position on enterframe

b) Modify Ceramic. I figure I’d add two variables for offset_x, and y. Change the signature of setCameraFocus to setCameraFocus(f, ox, oy). Set some default values of 0 here. The tricky part is modifying view.updateCamera(). From what’s there I’m guessing I can just add the offset to targetX and targetY at the end. Something like:

map.viewX=targetX+offset_x

map.viewY=targetY+offset_y

I probably could have tried this in the time it took me to write this post… Let me get back to you…

If it’s alright with you, I’m going to hurry up and finish Dusk, then all these questions can be asked and answered consistently (such as “do this”, rather than “with Ceramic, do this, but when Dusk comes, do this”). With Dusk, camera offsets work, “getting” a tile from an XY position works, etcetera, so if you can hang in there until I publish Dusk (not long now!), I can answer these for sure. That way, you won’t have to edit the library yourself :slight_smile:

In the meantime, (also for everyone else), check out the Dusk documentation (work in progress) here, to get a feel for the way Dusk works.

  • Caleb

Wow great, I can’t wait! Don’t feel you have to answer all of my questions, I’m just thinking out loud on the  forum. I understand you guys are working on the next version and the current version is sort of a beta that will be replaced. 

I teach a class on Corona and mobile app design, and was making some examples, and looking for ideas to show my students. 

Ok… The big day is coming up. The release is scheduled for this weekend (unless something unexpected happens). This release will be the public beta; feel free to pitch in with bug reports :). All that’s left right now is the final look-over and wrapping up for release.

Wish me luck :slight_smile:

  • Caleb

Been a lurker for a while, and I’m excited to see your hard work!

Woo hoo! Can’t wait. Thanks again! 

I’m replacing lime with Dusk in my android game Olethros and it is very impressive so far.
I hope version 1.9 will be Dusk Powered :smiley:
Good job guys!!

As a Christmas surprise, I’ve decided to release it early, namely…

Right now.

It’s live on GitHub at the normal repository, so give it a go.

@no2games:

The repository name and the description haven’t been changed yet, because I don’t have the permissions necessary to change it. If you would, kindly change it :slight_smile:

I’ve also closed a bunch of the bugs; thanks to everyone for sticking with Ceramic (and now Dusk) through the absence of updates lately - from now on, updates should be much more common.

  • Caleb :slight_smile: