簡體   English   中英

如何使用cocos python查找圖層寬度/高度

[英]How to find layer width/height with cocos python

我目前正在擺弄 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() )

我想要做的是在第一個標簽下方顯示第二個標簽,並將第一個標簽的三分之一向右移動。

有誰知道我如何獲得第一個標簽的寬度?

編輯:這是開發人員關於為什么沒有明確訪問權限的答案的問題。

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

最合適的似乎是

self.basic_text.element.content_width

從圖書館的快速瀏覽來看,這似乎被遺忘了。 同樣在他們的 API 中,這個參數根本沒有記錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM