15
15
from cocos import actions , layer , sprite , scene
16
16
from cocos .director import director
17
17
18
- # Player class
18
+ # Screen size
19
+ size = (800 ,600 )
19
20
21
+ # Arbitrary variable we include later in out text label, attention to the scope!
22
+ deltaTime = 42
23
+
24
+ # Player class called Me() <--- Needs better name
20
25
class Me (actions .Move ):
21
26
22
27
# step() is called every frame.
@@ -29,32 +34,38 @@ def step(self, dt):
29
34
30
35
# Set the object's velocity.
31
36
self .target .velocity = (velocity_x , velocity_y )
32
- # Main class
33
37
38
+ # Main class
34
39
def main ():
35
40
global keyboard # Declare this as global so it can be accessed within class methods.
36
41
# Initialize the window
37
- director .init (width = 500 , height = 300 , autoscale = True , resizable = True )
42
+ director .init (width = size [ 0 ] , height = size [ 1 ] , autoscale = True , resizable = True )
38
43
39
44
# Create a layer and add a sprite to it.
40
45
player_layer = layer .Layer ()
41
- me = sprite .Sprite ('sprites/molecule.png' )
42
- player_layer .add (me )
43
-
44
- # Add a Label, because we can
45
- label = cocos .text .Label ('Hello, world' , font_name = 'Times New Roman' , font_size = 32 , anchor_x = 'center' , anchor_y = 'center' )
46
- label .position = 250 , 150
46
+ molecule = sprite .Sprite ('sprites/molecule.png' )
47
+ molecule .scale = 2
48
+ player_layer .add (molecule , z = 1 )
49
+ scale = actions .ScaleBy (3 , duration = 2 )
50
+
51
+ # Add a Label, because we can.
52
+ label = cocos .text .Label ('Hello, world@' + str (deltaTime ), font_name = 'Times New Roman' , font_size = 32 , anchor_x = 'left' , anchor_y = 'center' )
53
+ label .position = 0 , size [1 ]/ 2
47
54
label .velocity = 0 , 0
48
55
player_layer .add (label )
49
56
50
57
# Set initial position and velocity.
51
- me .position = (100 , 100 )
52
- me .velocity = (0 , 0 )
58
+ molecule .position = (size [ 0 ] / 2 , size [ 1 ] / 2 )
59
+ molecule .velocity = (0 , 0 )
53
60
54
- # Set the sprite's movement class.
55
- #me.do(Me())
61
+ # Set the sprite's movement class and run some actions.
62
+ molecule .do (actions .Repeat (scale + actions .Reverse (scale )))
63
+
56
64
label .do (Me ())
57
65
66
+ # Rotate the entire player_layer (includes ALL nodes, will rotate ONCE)
67
+ player_layer .do (actions .RotateBy (360 , duration = 10 ))
68
+
58
69
# Create a scene and set its initial layer.
59
70
main_scene = scene .Scene (player_layer )
60
71
0 commit comments