Skip to content

Commit 3c89d8b

Browse files
committed
Added actors.py
1 parent 10c29ce commit 3c89d8b

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

assets/.DS_Store

-6 KB
Binary file not shown.

assets/img/.DS_Store

-6 KB
Binary file not shown.

basics/actors.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Here we will have the same starting code as we did in the last tutorial, except with a few different imports
2+
3+
import cocos
4+
from cocos.text import Label
5+
from cocos import scene
6+
from cocos.layer import Layer
7+
from cocos.director import director
8+
from cocos.sprite import Sprite
9+
10+
11+
class Actors(Layer):
12+
def __init__(self):
13+
super(Actors, self).__init__()
14+
15+
# Here is where the code starts to get different
16+
# Instead of text, I create a sprite object
17+
# Also unlike last time, I added the sprite to the object instead of making it local
18+
# This is useful if you want to access it in other functions, like I will show in the next tutorial
19+
self.actor = Sprite('assets/img/grossini_dance_08.png')
20+
21+
# Then I add it to the layer, similar to the text
22+
self.actor.position = 320, 240
23+
24+
# And lastly I add it to the layer. Standard stuff
25+
self.add(self.actor)
26+
27+
# Now I initialize the director and run the scene just like before
28+
director.init()
29+
director.run(scene.Scene(Actors()))
File renamed without changes.

basics/basics.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
Here is the order which the tutorial follows:
55

66
1. Getting Started (getting_started.py)
7-
2. Basic Actions (actions.py)
7+
2. Adding Actors (actors.py)
8+
3. Basic Actions (actions.py)

0 commit comments

Comments
 (0)