2015年12月12日土曜日

cocos helloworld



    C:\Python25\Lib\site-packages\cocos2d-0.4.0\samples\hello_world.py

# coding: UTF-8
# cocos2d
# http://cocos2d.org
#
# This code is so you can run the samples without installing the package
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
#上のコマンド、コメントアウトしてもこのファイル実行される
# sys.path.insert: モジュールを検索するディレクトリを追加する
# http://memo.jj-net.jp/173
# Pythonでプログラミングしていて,ちょっと別のディレクトリにあるモジュールをイ
# ンポートしたいときの話Pythonのモジュールを検索するディレクトリの一覧は
# sys.path というlistオブジェクトに収められています.このsys.pathはまったくの普
# 通のlistオブジェクトで挿入,削除,ソートなど何でもできてしまいます.このlist
# オブジェクにディレクトリのパスを現す文字列をついかすると import文でインポート
# するときのモジュール検索ディレクトリを増やすことができます.

# 上のパス関係だけを取り出し実行結果も記述したファイル↓
# C:\Python25\Lib\site-packages\cocos2d-0.4.0\samples\getcomposition.py

#このファイルの解説は以下にある
#file:///C:/Python25/Lib/site-packages/cocos2d-0.4.0/doc/html/programming_guide/hello_world.html
import cocos

class HelloWorld(cocos.layer.Layer):
    def __init__(self):
        super( HelloWorld, self ).__init__()

        # a cocos.text.Label is a wrapper of pyglet.text.Label
        # with the benefit of being a cocosnode
        label = cocos.text.Label('Hello, World!',
            font_name='Times New Roman',
            font_size=32,
            anchor_x='center', anchor_y='center')

        label.position = 320,240
        self.add( label )

if __name__ == "__main__":
    # director init takes the same arguments as pyglet.window
    cocos.director.director.init()

    # We create a new layer, an instance of HelloWorld
    hello_layer = HelloWorld ()

    # A scene that contains the layer hello_layer
    main_scene = cocos.scene.Scene (hello_layer)

    # And now, start the application, starting with main_scene
    cocos.director.director.run (main_scene)

    # or you could have written, without so many comments:
    #      director.run( cocos.scene.Scene( HelloWorld() ) )

0 件のコメント:

コメントを投稿

About

参加ユーザー

連絡フォーム

名前

メール *

メッセージ *

ページ

Featured Posts