2017-01-24 8 views
2

私は現在、Pythonとcocos2Dココスパイソンと層の幅/高さをどのように見つけるか

と周りいじるだと私はずっとこの

import cocos 
from cocos.director import director 

class MyLayer(cocos.layer.Layer): 

    def __init__(self): 
     #Setting the coordinate for the base layer 
     self.x = 200 
     self.y = 100 
     #A first layer of text 
     x_basic_text = 0 
     y_basic_text = 0 
     self.basic_text = cocos.text.Label("Unindented text", x=x_basic_text, y=y_basic_text) 
     #A second layer of text 
     y_indent_text = -20 #So that it doesn't squeeze with the basic text layer 
     x_indent_text = self.basic_text.width/3 #which doesn't work since layers have no width attribute 
     self.indent_text = cocos.text.Label("Indented text", x=x_indent_text, y=y_indent_text) 

director.init(resizable=True) 
director.run(MyLayer()) 

のようにインデントスペースでシンプルな表示をしたかった私は何最初のラベルの下に2番目のラベルを表示し、最初のラベルの3分の1を右に移動します。

どのように私はそうする最初のラベルの幅を得ることができる知っていますか?

編集:devsからの回答には、なぜ明確なアクセス権がないのかという問題があります。

https://github.com/los-cocos/cocos/issues/282

答えて

1

ベストフィットは、このが露出するように忘れられていたようだ図書館でクイックビューから

self.basic_text.element.content_width 

のようです。また、their APIには、このパラメータはまったく記載されていません。

+0

私は時間があるときはいつでも、自分のgithubページに問題を作ります。チェックありがとう! – YetAnotherStudent

関連する問題