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()
  • 相关阅读:
    P4839 P哥的桶 题解(线段树维护线性基)
    线性基入门
    Lowest Common Ancestor 题解(lca+思维)
    B
    java string对象的简单方法
    AtCoder Grand Contest 016 D
    FFT
    回文自动机(BZOJ2565)
    二维RMQ
    AC自动机(BZOJ1030)
  • 原文地址:https://www.cnblogs.com/fly-book/p/11769295.html
Copyright © 2011-2022 走看看