forked from los-cocos/cocos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.py
More file actions
46 lines (33 loc) · 1.3 KB
/
hello_world.py
File metadata and controls
46 lines (33 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# cocos2d
# http://python.cocos2d.org
#
from __future__ import division, print_function, unicode_literals
# This code is so you can run the samples without installing the package
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
#
import cocos
class HelloWorld(cocos.layer.Layer):
def __init__(self):
super(HelloWorld, self).__init__()
# a cocos.text.Label is a wrapper of pyglet.text.Label
# with the benefit of being a cocosnode
label = cocos.text.Label('Hello, World!',
font_name='Times New Roman',
font_size=32,
anchor_x='center', anchor_y='center')
label.position = 320, 240
self.add(label)
if __name__ == "__main__":
# director init takes the same arguments as pyglet.window
cocos.director.director.init()
# We create a new layer, an instance of HelloWorld
hello_layer = HelloWorld()
# A scene that contains the layer hello_layer
main_scene = cocos.scene.Scene(hello_layer)
# And now, start the application, starting with main_scene
cocos.director.director.run(main_scene)
# or you could have written, without so many comments:
# director.run( cocos.scene.Scene( HelloWorld() ) )