how to read a cell property

15 views
Skip to first unread message

Paolo

unread,
May 29, 2014, 9:10:08 AM5/29/14
to gummw...@googlegroups.com
Hello,
I found that maps created with Tiled program can add properties to single cells  (just like objects which can have properties).
It can be useful to give ids to some cells, for example to make someone gather some things on the map and to record which things have been gathered.
Is the cell property information stored somewhere in your Tiledmap object?

Paolo

bw

unread,
May 30, 2014, 11:34:06 PM5/30/14
to gummw...@googlegroups.com
Howdy,

The TiledMap, each TiledLayer, and each sprite has such properties.

For TiledMap this is done in the constructor.
For TiledLayer this is done in the constructor.
For sprites this is done in function tiledmap._load_tiled_tmx_map().

You can access a property like so: the_thing.properties['somename'].

Gumm
--
You received this message because you are subscribed to the Google Groups "Gummworld2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gummworld2+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

paolo

unread,
May 31, 2014, 3:54:02 AM5/31/14
to gummw...@googlegroups.com
Thank you, I found that the function _load_tiled_tmx_map() needs a small hack to gather the property I needed (the idx of image),
this is your code in tiledmap.py from line 185
          for ypos in xrange(0, layer.height):
                for xpos in xrange(0, layer.width):
                    x = (xpos + layer.x) * layer.tilewidth
                    y = (ypos + layer.y) * layer.tileheight
                    img_idx = layer.content2D[xpos][ypos]
                    if img_idx == 0:
                        continue
                    try:
                        offx,offy,tile_img = resource.indexed_tiles[img_idx]
                        screen_img = tile_img
                    except KeyError:
                        print 'KeyError',img_idx,(xpos,ypos)
                        continue
                    sprite = Sprite()
                   
                    sprite.image = screen_img
                    sprite.rect = screen_img.get_rect(topleft=(x + offx, y + offy))
                    sprite.name = xpos,ypos
                    #myhack to detect which is idx of image  in the sprite
                    sprite.img_idx=img_idx
                    #end of hack
                    gummworld_layer.add(sprite)



--
You received this message because you are subscribed to a topic in the Google Groups "Gummworld2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gummworld2/NxpmHBRFaTc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gummworld2+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages