pyxen.screen
从引擎访问屏幕尺寸信息。
screen = pyxen.screen
screen 模块提供:
- 当前屏幕宽度
- 当前屏幕高度
所有属性均为只读。
属性
| 属性 | 类型 | 描述 |
|---|---|---|
width | int | 屏幕宽度(像素) |
height | int | 屏幕高度(像素) |
width
w = pyxen.screen.width
返回当前屏幕宽度(像素)。
示例:
player.x = pyxen.screen.width / 2
height
h = pyxen.screen.height
返回当前屏幕高度(像素)。
示例:
player.y = pyxen.screen.height / 2
常见模式
居中实体
e = world.spawn(
x=pyxen.screen.width / 2,
y=pyxen.screen.height / 2
)
将 UI 保持在屏幕边缘
ui.x = pyxen.screen.width - 20
ui.y = 20
相对于屏幕的布局
margin = 16
panel_width = pyxen.screen.width - margin * 2
panel_height = pyxen.screen.height - margin * 2
与摄像机的交互
pyxen.screen 表示物理渲染表面。
它不考虑:
- 摄像机位置
- 摄像机旋转
- 摄像机缩放
摄像机变换影响世界渲染。
屏幕尺寸定义投影边界。
只读安全
所有属性均为只读:
pyxen.screen.width = 100 # Raises ValueError
屏幕尺寸由引擎内部管理。