cocos2d官方参考地址
http://python.cocos2d.org/doc/programming_guide/quickstart.html
精灵添加动作
import cocos
from cocos.actions import *
class HelloWorld(cocos.layer.ColorLayer):
def __init__(self):
super(HelloWorld, self).__init__(64, 64, 224, 225)
label = cocos.text.Label('Hello,World',
font_name='Times New Roman',
anchor_x='center',
anchor_y='center')
label.position = 320, 240
self.add(label)
sprite = cocos.sprite.Sprite('1.png')
sprite.position = 320, 240
sprite.scale = 3
# 添加精灵作为一个子节点,并且是在label的上面,所以设置z的值为1,默认z的值是0
self.add(sprite, z=1)
scale = ScaleBy(3, duration=2)
# # 标签做如下重复做如下动作,翻转放大2秒,然后一直做放大操作
label.do(Repeat(Reverse(scale) + scale))
if __name__ == '__main__':
cocos.director.director.init()
hello_layer = HelloWorld()
# 对整个层做翻转动作并且持续 10 秒
hello_layer.do(RotateBy(360, duration=10))
main_scene = cocos.scene.Scene(hello_layer)
cocos.director.director.run(main_scene)
网友评论