Skip to content

Commit 0f1ad08

Browse files
committed
tiled map support
1 parent dfd888a commit 0f1ad08

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

config.ini

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
name = Michael Foord
2-
# this comment belongs to 'DOB'
3-
DOB = 12th August 1974 # an inline comment
4-
nationality = English
1+
[Base]
2+
ressource_path = "./ressources"
3+
script_path = "./script"
54

5+
[Ressources]
6+
map1 = "./ressources/map/test.tmx"
7+
map2 = "./ressources/map/test2.tmx"
8+
map3 = "./ressources/map/test3.tmx"
9+
10+
[Text]
11+
font_name = "Times New Roman"
12+
font_size = 32
13+
14+
[Window]
15+
width = 800
16+
height = 600
617

718

819

main.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import cocos
2+
import os
3+
import configobj_ext
4+
import tiled2cocos
5+
6+
DEFAULT_PATH = "./config.ini"
7+
DEFAULT_SPEC = "./config_spec.ini"
8+
9+
def app_path(rel_path):
10+
application_path = os.path.dirname(__file__)
11+
return os.path.join(application_path, rel_path)
12+
13+
def load_config():
14+
path = app_path(DEFAULT_PATH)
15+
spec = app_path(DEFAULT_SPEC)
16+
config = configobj_ext.read_config(path, configspec=spec)
17+
return config
18+
19+
def prepare(config):
20+
cocos.director.director.init(width=config.Window.width, height=config.Window.height)
221

322
class HelloWorld(cocos.layer.Layer):
423
def __init__(self):
524
super( HelloWorld, self ).__init__()
625

7-
label = cocos.text.Label('Hello, World!',
26+
label = cocos.text.Label('Gros bisous Even'.upper(),
827
font_name='Times New Roman',
928
font_size=32,
1029
anchor_x='center', anchor_y='center')
@@ -13,7 +32,17 @@ def __init__(self):
1332
self.add( label )
1433

1534
if __name__ == "__main__":
16-
cocos.director.director.init()
35+
config = load_config()
36+
prepare(config)
37+
map_layer = tiled2cocos.load_map(config.Ressources.map3)
38+
map_layer.set_view(0, 0, config.Window.width, config.Window.height)
39+
#map_layer.x = config.Window.width / 2.0
40+
#map_layer.y = config.Window.height / 2.0
41+
for c in map_layer.get_children():
42+
print c
43+
c.do(cocos.actions.RotateBy( 360, duration=2 ))
1744
hello_layer = HelloWorld ()
18-
main_scene = cocos.scene.Scene (hello_layer)
45+
main_scene = cocos.scene.Scene (*[map_layer, hello_layer])
46+
hello_layer.do( cocos.actions.RotateBy( 720, duration=5 ))
47+
1948
cocos.director.director.run (main_scene)

0 commit comments

Comments
 (0)