forked from liamrahav/cocos2d-python-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactors.py
More file actions
29 lines (22 loc) · 1.01 KB
/
actors.py
File metadata and controls
29 lines (22 loc) · 1.01 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
# Here we will have the same starting code as we did in the last tutorial, except with a few different imports
import cocos
from cocos.text import Label
from cocos import scene
from cocos.layer import Layer
from cocos.director import director
from cocos.sprite import Sprite
class Actors(Layer):
def __init__(self):
super(Actors, self).__init__()
# Here is where the code starts to get different
# Instead of text, I create a sprite object
# Also unlike last time, I added the sprite to the object instead of making it local
# This is useful if you want to access it in other functions, like I will show in the next tutorial
self.actor = Sprite('assets/img/grossini.png')
# Then I add it to the layer, similar to the text
self.actor.position = 320, 240
# And lastly I add it to the layer. Standard stuff
self.add(self.actor)
# Now I initialize the director and run the scene just like before
director.init()
director.run(scene.Scene(Actors()))