Skip to content

Commit 9ff9095

Browse files
committed
- Renamed the sprite to molecule, added label with a variable, added actions to scale (forever) the sprite back and forth, rotated the entire player_layer once with an action
1 parent 4ce4a50 commit 9ff9095

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

cocos-test.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515
from cocos import actions, layer, sprite, scene
1616
from cocos.director import director
1717

18-
# Player class
18+
# Screen size
19+
size = (800,600)
1920

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
2025
class Me(actions.Move):
2126

2227
# step() is called every frame.
@@ -29,32 +34,38 @@ def step(self, dt):
2934

3035
# Set the object's velocity.
3136
self.target.velocity = (velocity_x, velocity_y)
32-
# Main class
3337

38+
# Main class
3439
def main():
3540
global keyboard # Declare this as global so it can be accessed within class methods.
3641
# 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)
3843

3944
# Create a layer and add a sprite to it.
4045
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
4754
label.velocity = 0, 0
4855
player_layer.add(label)
4956

5057
# 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)
5360

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+
5664
label.do(Me())
5765

66+
# Rotate the entire player_layer (includes ALL nodes, will rotate ONCE)
67+
player_layer.do(actions.RotateBy(360, duration=10))
68+
5869
# Create a scene and set its initial layer.
5970
main_scene = scene.Scene(player_layer)
6071

0 commit comments

Comments
 (0)