Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Using Tiled — Gideros Forum

Using Tiled

mykyl66mykyl66 Member
edited March 2012 in General questions
I have looked and looked at the sewer code and desert code (No comments in that code still. When will we see commented code in the samples?) and cannot figure out what is happening.

How do you use a file from TilEd simply. For example lets say you did a line of tiles in TilEd that will be a platform game how do I then use that TileEd file to draw that platform to screen.

Cheers

Mike
What would you do for your other half?

http://www.sharksoupstudios.com
«1

Comments

  • mykyl66mykyl66 Member
    edited March 2012
    Never mind. Got it I think.

    Mike
    What would you do for your other half?

    http://www.sharksoupstudios.com
  • atilimatilim Maintainer
    Oh.. I was just preparing an example. :) If you stuck, please ask again.
  • Probably would be good to post it anyway for others as its not very clear and took quite a bit of figuring out.

    Cheers

    Mike

    Likes: WauloK, Harrison

    What would you do for your other half?

    http://www.sharksoupstudios.com
    +1 -1 (+2 / -0 )Share on Facebook
  • I'm just looking at Tiled as an option since I can't use Levelhelper with Gideros (I'm moving over from Corona), so a tutorial on tiled & gideros would be gratefully appreciated.
  • The code to display a tiled map is hurting my head. could someone break it down?
  • atilimatilim Maintainer
    Hi all,

    Tile map file format is a little bit complicated. Because it can contain multiple tilesets and multiple layers. But if there is only 1 tileset and 1 layer, loading function can be simplified. Here is an explanation of TMX file format: https://github.com/bjorn/tiled/wiki/TMX-Map-Format The exported lua file has the same structure.

    I've separated the tile map loading functionality into classes. The attached zip file contains two classes: TileMapSingle and TileMapMultiple. TileMapSingle can be used when there is only 1 tileset and 1 layer. Otherwise you should use TileMapMultiple.

    Hope this helps.
    zip
    zip
    Tile Map Example.zip
    30K

    Likes: Yan, MoKaLux

    +1 -1 (+2 / -0 )Share on Facebook
  • evsevs Member
    I've added this at line 36 of tilemapsingle.lua to allow translucency in a single layer (in case you have a background visible already, see below).
    tilemap:setAlpha(layer.opacity)
    Note: tilemapmultiple.lua already does this to all layers in the group.


    Cheers

    evs
    Trans-Lucent Express.png
    464 x 175 - 23K

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • I was wondering if there are any examples on detecting walls that are in a tilemap (as a separate layer)

    Cheers

    Gary
  • evsevs Member
    Here's a little demo featuring a Tiled tile map with a tile layer for the graphics and an object layer for building physics collision zones and storing properties.

    Grab the ball and chuck it about, see the various collisions and scores printed out, set the debug flag in the code to see debug drawing and object info.

    Thanks go to @atilim for the initial tile stuff and Gideros collision example
    and to @ar2rsawseen for the main physics stuff and appcodingeasy.

    All files including a gproj and the Tiled tmx are included.


    cheers

    evs

    Gideros Tilemap.png
    664 x 532 - 49K
    zip
    zip
    Tiled Demo.zip
    60K

    Likes: Garyk1968

    +1 -1 (+1 / -0 )Share on Facebook
  • gorkemgorkem Maintainer
    @evs do you mind adding this post to the Code snippets section also, so I can link it from Forum FAQ?
  • evsevs Member
    edited May 2012
    @gorkem no problem - done!


    cheers

    evs
  • evs thanks for your efforts it *is* appreciated!
  • gorkemgorkem Maintainer
    *More than* appreciated ;-)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • Hi all,

    Tile map file format is a little bit complicated. Because it can contain multiple tilesets and multiple layers. But if there is only 1 tileset and 1 layer, loading function can be simplified. Here is an explanation of TMX file format: https://github.com/bjorn/tiled/wiki/TMX-Map-Format The exported lua file has the same structure.

    I've separated the tile map loading functionality into classes. The attached zip file contains two classes: TileMapSingle and TileMapMultiple. TileMapSingle can be used when there is only 1 tileset and 1 layer. Otherwise you should use TileMapMultiple.

    Hope this helps.

    very handy classes.
    I'm a little confused by the these two lines.
    It's OK since the margin is much smaller than tilewidth in most tileset.
    tileset.sizex = math.floor((tileset.imagewidth - tileset.margin + tileset.spacing) / (tileset.tilewidth + tileset.spacing))
    		tileset.sizey = math.floor((tileset.imageheight - tileset.margin + tileset.spacing) / (tileset.tileheight + tileset.spacing))
    why not as following
    tileset.sizex = math.floor((tileset.imagewidth - 2 * tileset.margin + tileset.spacing) / (tileset.tilewidth + tileset.spacing))
    		tileset.sizey = math.floor((tileset.imageheight - 2 * tileset.margin + tileset.spacing) / (tileset.tileheight + tileset.spacing))
  • alexzhengalexzheng Guru
    edited June 2012
    Sorry,I have never used tilemap in a real game,so I have many question when looking into the code.
    And in this function
    why we do not mask bit 32, 31 and 30 of gid when find out the tileset according to this document:
    When you use the tile flipping feature added in Tiled Qt 0.7.0, the highest two bits of the gid store the flipped state. Bit 32 is used for storing whether the tile is horizontally flipped and bit 31 is used for the vertically flipped tiles. And since Tiled Qt 0.8.0, bit 30 means whether the tile is flipped (anti) diagonally, enabling tile rotation. These bits have to be read and cleared before you can find out which tileset a tile belongs to.
    local function gid2tileset(map, gid)
    	for i=1, #map.tilesets do
    		local tileset = map.tilesets[i]
     
    		if tileset.firstgid <= gid and gid <= tileset.lastgid then
    			return tileset
    		end
    	end
    end
  • alexzhengalexzheng Guru
    edited June 2012
    and the "gids" is an array of unsigned 32-bit integers using little-endian byte ordering,will swap byte needed for big-endian Architecture?
  • Hi,

    When I try to implement the TileMapMultiple I get the following error

    tileMapMultiple.lua:32: 'for' limit must be a number

    which is this line of code:

    for y=1,layer.height do

    Any ideas? My tilemap has two layers, and one tileset.

    Thanks for your help

    James
  • It would appear that the layer.height is nil for the particular layer you're trying to process.
  • Thanks Scouser, I had a look at the map lua file, and compared it to another, and you were right, the layer in my new map didn't have a "height" or "width" attribute, and another map did. I'll give it a go and see if it works.

    Cheers

    James
  • How do we make shapes other than boxes? Eg a slope?

    Thanks
  • I've tried the TiledAsWorldEditor V2 example but a required module named "bit" seems to be missing from the project. Is this a plugin of Gideros? I found a "bit.c" in "All Plugins" folder of Gideros. Should I compile it to DLL? I am a bit new in Gideros Mobile so please forgive my ignorance.
  • OK I found out how it works. I needed to put the bitop.dll file in the \Plugins folder and to restart the player... Thanks anyway.
  • hgvyas123hgvyas123 Guru
    edited April 2013
    @brigosx

    i dont think we need bit plugin to run tilemap are you using any third party tool or i am missing something?

    :)
  • ar2rsawseenar2rsawseen Maintainer
    @hgvyas123 :)
    I've tried the TiledAsWorldEditor V2 example but a required module named "bit" seems to be missing from the project. Is this a plugin of Gideros? I found a "bit.c" in "All Plugins" folder of Gideros. Should I compile it to DLL? I am a bit new in Gideros Mobile so please forgive my ignorance.
  • hgvyas123, no I've just downloaded the demo and ran it from within the Gideros SDK on the Windows player. There is a require "bit" inside the class body but I am not sure why mine installation demanded it (it has a condition there too).

    Likes: hgvyas123

    +1 -1 (+1 / -0 )Share on Facebook
  • I am currently pondering wether to use Gideros TileMap or an own tile map solution for my project because Gideros' TileMap documentation is very poor and the examples leave lots of questions, too.

    Are there any performance benefits from using Gideros' TileMap instead of a custom tile map solution?

    And what is a "gid"?
    local function gid2tileset(gid)
    	for i=1, #map.tilesets do
    		local tileset = map.tilesets[i]
    		if tileset.firstgid <= gid and gid <= tileset.lastgid then
    			return tileset
    		end
    	end
    end

  • @MauMau
    1) I would suggest using Gideros TileMap implementation because it will be much more optimized internally, then simply putting Bitmaps in your own solution

    2) I have not used Tiled myself, but as I see from example, in Tiled, if you have multiple tile set images, then they would be indexed together, as if first tiles set contains 16 images, first one would be 1st, last one would be 16th, and the next tile set first tile would start with 17th index.
    So gid is a global tile identifier across all provide tile sets, and this function is what finds the correct tile set for specified identifier.
    Basically it is something specific to Tiled export.

Sign In or Register to comment.