cocos2d-python error loading Tiled (.tmx) map

Greetings:

I am aware that this is a forum dedicated to the discussion of cocos-x and not cocos-python, but the cocos-python community on Google groups is virtually “dead”.

I’ve Googled my error to the best of my abilities, but there are no definative answers to my problem.

I am currently following the documentation at http://python.cocos2d.org/doc/programming_guide/tiled_map.html#controlling-map-scrolling to load a Tiled (.tmx) orthogonal map into my game. Now I am loading my .tmx map into the game via the following Python code:

map = cocos.tiles.load("mymap.tmx")

However, this line of code raises the following error:

'Resource' object has no attribute 'set_view'

Now the weird thing is that the following line of code bypasses that issue, but the drawback is that it only loads one layer on my Tiled (.tmx) map.

map = cocos.tiles.load("mymap.tmx")['layer1']

I can’t seem to figure out why this error is being raised, but I am hoping someone with a good understanding of cocos can aid me.

Thanks a ton!

Why you don’t use cocos2dx? You can follow this tutorial: http://www.raywenderlich.com/39113/cocos2d-x-tile-map-tutorial-part-1

whilst the question might be out of place, your reply isn’t a valid answer. He wasn’t asking for engine recomendations, he was asking a question about the TMX loader in Cocos2d original

lol thanks for your reply 1 year later, but you don’t provide the right answer… At least, its possible that my reply had helped some people who clicked the link, so I think your reply is even worst than mine :wink:

Actually, panor, I found this while searching for a solution to a problem I’m having (the same problem Pythong is having), and your response was so frustratingly useless I decided to make an account just to point that out.

As for the question itself, I actually found a solution elsewhere (again, no thanks to panor >.>). You’re on the right track with your work around. It seems cocos.tiles.load(filename) returns a cocos.tiles.Resource object, which functions a bit like a dictionary- that ‘layer1’ you used would be the key, while the value is the map layer it yields. You can use the find(cls) method of the cocos.tiles.Resource object to find all instances of cocos.tiles RectMapLayer like so:

maps = map.find(cocos.tiles.RectMapLayer)

This will return a generator which returns a tuple of key/value pairs, with the value being the second item of the tuple. You can use this generator in a for loop to iteratively add all layers in your map.

for i in maps:
    scene.add(i[1])
    i.set_view(*x, y, w, h, viewport_x=0, viewport_y=0*) 
    #You'll recognize the above method from the part of the tutorial you linked.