14
14
# Here I make a class that extends cocos' ColorLayer class
15
15
# This type of layer is different because it has a background color! (awesome right?)
16
16
class Actions (ColorLayer ):
17
- # When I initialize it I need to pass in an RRGB colour value so it can set the ColorLayer's background
17
+ # When I initialize it I need to pass in an RGBA colour value so it can set the ColorLayer's background
18
18
# I grabbed the Peter River colour (#3498db) from http://flatuicolors.com for this sample
19
19
def __init__ (self ):
20
- super (Actions , self ).__init__ (52 , 52 , 152 , 219 )
20
+ super (Actions , self ).__init__ (52 , 152 , 219 , 1000 )
21
21
22
22
# I initialize a sprite using the cocos sprite.Sprite class
23
23
# Change the path below to whatever your sprite image is
@@ -30,8 +30,12 @@ def __init__(self):
30
30
# Check those class functions for info on how to code them!
31
31
self .fade_in ()
32
32
self .move_left ()
33
- self .move_right ()
34
- self .move_right ()
33
+
34
+ # It's important to note that placing actions one after another can often lead to issues
35
+ # For example, if you told the sprite to move left one and then move right twice, it would only move right once
36
+ # This is because python executes the code so quickly that it doesn't have time to complete the first animations
37
+ # Using the typical time.sleep from the time builtin doesn't work either, because it stops the entire game
38
+ # Therefore, actions are best suited for user input, not cutscenes or animations
35
39
36
40
def fade_in (self ):
37
41
# First I make a FadeIn animation object
@@ -48,30 +52,14 @@ def fade_in(self):
48
52
# I don't need to reset the opacity because the FadeIn action does that for me!
49
53
self .sprite .do (fade_action )
50
54
51
- def move_left (self , sleep_time = 2 ):
55
+ def move_left (self ):
52
56
# First I make a MoveBy animation object
53
57
# I set this to move -150 on the X axis, 0 on the Y axis, and to take 2 seconds
54
58
left = MoveBy ((- 150 , 0 ), 2 )
55
59
56
60
# Finally I make my sprite move left
57
61
self .sprite .do (left )
58
62
59
- # I need to make the program sleep so that it lets this animations finish
60
- sleep (sleep_time )
61
-
62
- def move_right (self , sleep_time = 2 ):
63
- # If you notice, this method is exactly the same as the move left method, but it moves +150 instead of -150
64
-
65
- # First I make a MoveBy animation object
66
- # I set this to move +150 on the X axis, 0 on the Y axis, and to take 2 seconds
67
- right = MoveBy ((150 , 0 ), 2 )
68
-
69
- # And I make my sprite move right (just like in left)
70
- self .sprite .do (right )
71
-
72
- # Again I need my program to sleep for the 2 seconds the animation requires
73
- sleep (sleep_time )
74
-
75
63
76
64
# I initialize the director and run the layer (this is typical for cocos programs)
77
65
director .init ()
0 commit comments