5
# This code is so you can run the samples without installing the package
8
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
12
from cocos.director import director
16
# Defining a new layer type...
17
class Square(cocos.layer.Layer):
18
"""Square (color, c, y, size=50) : A layer drawing a square at (x,y) of
19
given color and size"""
20
def __init__(self, color, x, y, size=50):
21
super( Square, self ).__init__()
26
self.layer_color = color
29
super(Square,self).draw()
31
gl.glColor4f(*self.layer_color)
33
w = x+self.size; h=y+self.size
34
gl.glBegin(gl.GL_QUADS)
42
if __name__ == "__main__":
44
# Create a large number of layers
45
layers = [ Square((0.03*i,0.03*i,0.03*i,1) , i*20, i*20) for i in range(5,20) ]
46
# Create a scene with all those layers
47
sc = cocos.scene.Scene(*layers)
48
# You can also add layers to a scene later:
49
sc.add( Square((1,0,0,0.5), 150,150, 210 ), name="big_one" )