On Mon, Aug 5, 2013 at 10:01 PM, Brandon Jumbeck <[email protected]>wrote:
> Hey guys, so I am having a bit of trouble with using Tiled Map Editor and
> Cocos2D. Many I am having trouble find cell properties to handle stuff like
> collision and spawning and other stuff.
>
> From my understanding start = tilemap.find_cells(player_start = True)[0]
> should return the cell that contains the property called player_start thats
> value is equal to True.
>
More exactly
tilemap.find_cells(player_start = True)
will return a list of the cells which have a property called player_start
and it's value is True.
adding [0] will try to get the first element in that list; but if the list
is empty will raise an IndexError
That is true for the original .xml format used by cocos, which stores
properties in the cell objects.
But looking at the .tmx loader ( cocos.tiles.load_tmx ) I see
cells[i][j] = RectCell(i, j, tile_width, tile_height, {}, tile)
which sets an empty dict for the cell properties.
It has some logic, because tmx seems to attach properties only to tiles,
not cells, but renders unusable find_cells
This can be fixed by copying the tile properties to the cell properties
after loading the map.
I attach test_tmx_properties.py exercising a function to do that (read the
docstring to know how to run)
> I currently am using a tile in Tiled that has these properties but yet it
> keep telling me I am accessing a out of range element in the list (Meaning
> there is nothing in it)
>
. Am I doing it wrong or am I labeling the properties wrong or using the
> wrong function?
>
Not your fault, It is not stated that .xml and .tmx loaded map are
different.
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
test_tmx_properties.py
Description: Binary data
