How i load a tiled map?

45 views
Skip to first unread message

Antoni Rocafort

unread,
Jan 21, 2021, 4:59:08 PM1/21/21
to cocos2d discuss

Hello I'm developing a game with cocos2d in python. I am trying load a tiled map, but i have problems with it.

1-Large time of loading a tmx file.

2-Atribute error while loading the tiled map.

My code:

class Level(Scene):
def __init__(self):
super().__init__()
cha = Character()
bg = load_tmx("maps/space_map_2.tmx")["space"]
character_layer = ScrollingManager()
character_layer.add(bg) character_layer.add(cha)
self.add(character_layer)

How can i reduce the loading time?

Traceback (most recent call last): File "***/PycharmProjects/smashking/Main.py", line 74, in <module> escena_2 = Level() File "***/PycharmProjects/smashking/Levels.py", line 13, in __init__ character_layer.add(bg) File "***/PycharmProjects/course/venv/lib/python3.8/site-packages/cocos/layer/scrolling.py", line 295, in add self.set_focus(self.fx, self.fy, force=True) File "***/PycharmProjects/course/venv/lib/python3.8/site-packages/cocos/layer/scrolling.py", line 373, in set_focus return self.force_focus(fx, fy) File "***/PycharmProjects/course/venv/lib/python3.8/site-packages/cocos/layer/scrolling.py", line 481, in force_focus layer.set_view(childs_scroll_x, childs_scroll_y, w, h, AttributeError: 'TileSet' object has no attribute 'set_view'

Why is getting this error while loading?

claudio canepa

unread,
Jan 21, 2021, 5:06:43 PM1/21/21
to cocos2d discuss
could you paste the code and traceback on some pastebin, by example https://pastebin.com ?

--
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 cocos-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocos-discuss/c222af1f-abb9-49df-8413-7d553b6ba813n%40googlegroups.com.

Toni Roca

unread,
Jan 22, 2021, 4:12:19 AM1/22/21
to cocos2d discuss


El dia dijous, 21 de gener de 2021 a les 23:06:43 UTC+1, Claudio Canepa va escriure:

Toni Roca

unread,
Jan 22, 2021, 6:26:54 AM1/22/21
to cocos2d discuss
Its crashes when:

characted_layer.add(bg)

El dia divendres, 22 de gener de 2021 a les 10:12:19 UTC+1, Toni Roca va escriure:

claudio canepa

unread,
Jan 22, 2021, 3:05:55 PM1/22/21
to cocos2d discuss
The last line in the traceback,
layer.set_view(childs_scroll_x, childs_scroll_y, w, h, AttributeError: 'TileSet' object has no attribute 'set_view' 
implies bg was read as a Tileset object, when it should be a RectMapLayer or HexMapLayer.

bg comes from
bg = load_tmx("maps/space_map_2.tmx")["space"]

Maybe "space" is not the correct selector?

Other than that, I will need to look at the tmx to tell more.


Toni Roca

unread,
Jan 22, 2021, 5:19:20 PM1/22/21
to cocos2d discuss
I solved  it, chaging the tmx for another one more tiny.

El dia divendres, 22 de gener de 2021 a les 21:05:55 UTC+1, Claudio Canepa va escriure:
Reply all
Reply to author
Forward
0 new messages