如何使用cocos python查找层宽度/高度

2024-09-28 21:28:44 发布

您现在位置: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


Tags: ofthetextimportselflayerbasicinit
1条回答
网友
1楼 · 发布于 2024-09-28 21:28:44

最合适的似乎是

self.basic_text.element.content_width

从图书馆的一个快速的视角看,这似乎是忘记了被曝光。同样在their API中,这个参数根本没有文档记录。在

相关问题 更多 >