【问题标题】:Cocos2d scene only taking quarter of screen, how do I fix it?Cocos2d 场景只占屏幕的四分之一,我该如何解决?
【发布时间】:2019-12-17 20:09:10
【问题描述】:

我正在尝试创建一个非常基本的 cocos2d 程序,但场景从左下角到窗口中间只占窗口的 1/4。

我尝试使用 scene.position= x,y 更改场景的位置,但 cocos 似乎将窗口的中间视为其右上角。

import cocos
from cocos.director import director

if __name__ == '__main__':
    director.init(
        fullscreen=False, width=1280, height=800)
    hello_layer = HelloCocos() #Grey ColorLayer and a "Hello" label on it.
    test_scene = cocos.scene.Scene(hello_layer)
    test_scene.position = 0, 600

    director.run(test_scene)

You can see here 场景没有越过窗口中间。 全屏下没问题,场景占满整个屏幕。 如何让场景占据整个窗口?让它变大也无济于事,它只是从底部和左侧边缘脱落。

【问题讨论】:

    标签: cocos2d-python


    【解决方案1】:

    在 cocos 中,场景的锚点默认为 (0.5, 0.5)。这意味着场景的 (0, 0) 位于其中心。

    当您将场景定位在 (0, 600) 时,您是说场景的中心位于窗口(可见区域)的 (0, 600)。

    现在,我假设您的场景大小和窗口大小都是 width=1280,height=800。这将使部分场景走出窗外。特别是在左上角。

    Here is a reference image to explain the same

    要使场景居中,您可能希望将场景定位在可见区域(窗口)的中心 (640, 400)。或者将其锚点显式设置为 (0, 0),并将位置设置为 (0, 0)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      相关资源
      最近更新 更多