Skip to content

Commit 1e8b4e5

Browse files
loader working again
1 parent 0d221df commit 1e8b4e5

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

tiless-editor/map-big.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"layers": [{"layer_type": "sprite", "z": 0, "data": {"sprites": [{"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-117.0, -24.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [121.0, 157.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [38.0, -104.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-366.0, 238.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-265.0, 67.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [9.0, 163.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-218.0, -195.0], "rotation": 0, "filename": "tiles/set4/Character Cat Girl.png", "rect": [206, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-53.0, 72.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-63.0, 67.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [221.0, -43.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-164.0, 238.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [233.0, 147.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-164.0, 67.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-164.0, -104.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-326.0, 161.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-112.0, -33.0], "rotation": 55, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [287.0, -195.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [139.0, -104.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-265.0, -104.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [279.0, 46.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-113.0, 154.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-225.0, 157.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 162.3363593445001, "scale": 1, "z": 0, "label": null, "position": [-16.0, -24.0], "rotation": 0, "filename": "tiles/set4/Character Cat Girl.png", "rect": [206, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [139.0, 238.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-275.0, 64.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-172.0, 58.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-50.0, -130.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [46.0, -129.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [59.0, 66.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [38.0, 238.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-117.0, -195.0], "rotation": 0, "filename": "tiles/set4/Character Cat Girl.png", "rect": [206, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-265.0, 238.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-366.0, -104.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-16.0, -195.0], "rotation": 0, "filename": "tiles/set4/Character Cat Girl.png", "rect": [206, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-4.0, -22.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [105.0, -33.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [159.0, -133.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-218.0, -195.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-63.0, 238.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [38.0, 67.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-366.0, 67.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [139.0, 67.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-222.0, -36.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [169.0, 57.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-265.0, 238.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 162.3363593445001, "scale": 1, "z": 0, "label": null, "position": [85.0, -24.0], "rotation": 0, "filename": "tiles/set4/Character Cat Girl.png", "rect": [206, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [287.0, -24.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-16.0, -195.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-63.0, -104.0], "rotation": 0, "filename": "tiles/set4/Character Boy.png", "rect": [103, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [287.0, 147.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [85.0, -195.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 162.3363593445001, "scale": 1, "z": 0, "label": null, "position": [186.0, -24.0], "rotation": 0, "filename": "tiles/set4/Character Cat Girl.png", "rect": [206, 0, 101, 171]}, {"opacity": 248.63095651637462, "scale": 1.5236458388066785, "z": 0, "label": null, "position": [-172.0, -135.0], "rotation": 64.945997861600944, "filename": "tiles/set4/Character Princess Girl.png", "rect": [515, 0, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-319.0, -195.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [186.0, -195.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}, {"opacity": 255, "scale": 1, "z": 0, "label": null, "position": [-319.0, -24.0], "rotation": 0, "filename": "tiles/set4/Gem Green.png", "rect": [206, 173, 101, 171]}]}, "label": "sprite layer (0)"}], "tilesdir": "tiles/set4"}

tiless-editor/map-small.png

Lines changed: 1 addition & 0 deletions
Loading

tiless-editor/tilesslayer.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,33 @@ def load_atlas( self, atlasfile ):
7676
def parse_json_file( self, jsonfile ):
7777
'''data parser'''
7878

79-
layers_dict = simplejson.load(open( jsonfile ))['layers']
79+
layers_list= simplejson.load(open( jsonfile ))['layers']
8080

81-
for key in layers_dict.keys():
82-
current_layer = layers_dict[key]
83-
batch = BatchNode()
81+
for layer in layers_list:
8482

85-
sprites = current_layer.get('sprites',[])
86-
for sprite in sprites:
87-
rect = sprite['rect']
88-
region = pyglet.image.TextureRegion( rect[0], rect[1], 0, rect[2], rect[3], self.atlas.texture )
83+
type = layer['layer_type']
8984

90-
s = Sprite( region, sprite['position'], sprite['rotation'], sprite['scale'], sprite['opacity'])
91-
if "label" in sprite:
92-
s.label = sprite['label']
85+
if type == 'sprite':
9386

94-
batch.add( s )
95-
self.add( batch )
87+
z = layer.get('z',0)
88+
sprites = layer.get('data',[])
89+
batch = BatchNode()
90+
91+
for sprite in sprites['sprites']:
92+
rect = sprite['rect']
93+
region = pyglet.image.TextureRegion( rect[0], rect[1], 0, rect[2], rect[3], self.atlas.texture )
94+
95+
s = Sprite( region, sprite['position'], sprite['rotation'], sprite['scale'], sprite['opacity'])
96+
if "label" in sprite:
97+
s.label = sprite['label']
98+
99+
batch.add( s )
100+
self.add( batch, z=z )
96101

97102

98103
if __name__ == "__main__":
99104
director.init(width=800, height=600, fullscreen=False)
100105
test_layer = TilessLayer('map.json', 'atlas-fixed.png')
101106
main_scene = cocos.scene.Scene (test_layer)
107+
main_scene.scale = 0.3
102108
director.run (main_scene)

0 commit comments

Comments
 (0)