zoukankan      html  css  js  c++  java
  • 02.action--新增精灵知识点

    import cocos
    from cocos.actions import *
    
    
    class HelloWorld(cocos.layer.ColorLayer):  # ColorLayer子类化为具有背景色
        def __init__(self):
            # r,g,b,a 蓝色
            super(HelloWorld, self).__init__(64, 64, 224, 255)
            # 添加标签
            label = cocos.text.Label(
                'hellow,action',
                font_name='Times New Roman',
                font_size=32,
                anchor_x='center',
                anchor_y='center'
            )
            label.position = 320, 240
            self.add(label)
            # 精灵是Sprite对象
            sprite = cocos.sprite.Sprite('cat.png')
            # 将精灵放置在屏幕的中央,默认位置是(0,0)
            sprite.position = 320, 240
            # 精灵将大3倍,默认比例属性为1
            sprite.scale = 3
            # 将精灵作为子级添加到标签的顶部,默认的z值为0
            self.add(sprite, z=1)
            # 在2秒内缩放对象的3倍,duration:持续时间
            scale = ScaleBy(3, duration=2)
            # 标签在2秒内缩放3倍,然后在2秒内缩小3倍,重复执行这2个操作
            # Repeat:重复
            label.do(Repeat(scale + Reverse(scale)))
            # 精灵先缩小再放大
            sprite.do(Repeat(Reverse(scale) + scale))
    
    
    def main():
        # 初始化导演
        cocos.director.director.init()
        hello_layer = HelloWorld()
        # 在10秒内执行360度的旋转动作
        hello_layer.do(RotateBy(360, duration=10))
        # 创建场景
        main_scene = cocos.scene.Scene(hello_layer)
        cocos.director.director.run(main_scene)
    
    
    if __name__ == '__main__':
        main()
  • 相关阅读:
    阅读《构建之法》
    准备工作
    课程总结
    第十四周总结
    第十三周总结
    Flex撑开
    多行文本展示为省略号样式的react组件
    如何在Spring Boot 中动态设定与执行定时任务
    System.arraycopy() 和 Arrays.copyOf() 的区别说明
    使用反射机制,获取 ArrayList 的容量大小
  • 原文地址:https://www.cnblogs.com/fly-book/p/11769295.html
Copyright © 2011-2022 走看看