01.helloworld--标签

戏子无情 提交于 2019-12-03 01:27:28
"""参考网站:http://python.cocos2d.org/doc/programming_guide/quickstart.html"""
import cocos


class HelloWord(cocos.layer.Layer):  # 继承层
    def __init__(self):
        super(HelloWord, self).__init__()
        # 创建一个标签来显示文字,设置标签的字体,位置和对齐方式:
        label = cocos.text.Label(
            'Hello,world',
            font_name='Times New Roman',
            font_size=32,
            anchor_x='center',  # 锚点x
            anchor_y='center'
        )
        # 标签位置
        label.position = 320, 240
        self.add(label)  # 作为子类添加到层


def main():
    # 初始化导演
    cocos.director.director.init()
    hello_layer = HelloWord()
    # 创建一个包含HelloWorld图层作为子场景的场景
    main_scene = cocos.scene.Scene(hello_layer)
    # 运行场景
    cocos.director.director.run(main_scene)


if __name__ == '__main__':
    main()

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!