pyxen.input.touches
访问触摸屏输入(移动设备和平板电脑)。
touches = pyxen.input.touches
检测触摸支持
if input.touches.present:
log("platform supports touches")
迭代
for t in touches:
if t.started:
print(t.id, t.pos)
索引
if len(touches) > 0:
pos = touches[0].pos
player.x = pos.x
Touch 对象
每个 Touch 暴露:
| 属性 | 类型 | 描述 |
|---|---|---|
id | int | 唯一触摸 ID |
pos | Vector2 | 位置 |
delta | Vector2 | 移动量 |
pressure | float | 压力(如果支持) |
started | bool | 第一帧为 True |
ended | bool | 释放时为 True |
所有字段都是只读的。
计数
count = touches.count
或
len(touches)
示例:点击检测
for t in touches:
if t.started:
spawn_explosion(t.pos)
注意事项
- 最大触摸数由引擎定义
- 安全迭代
- 索引越界会引发错误