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 暴露:

属性类型描述
idint唯一触摸 ID
posVector2位置
start_posVector2触摸开始时的位置(在其生命周期内保持不变)
deltaVector2移动量
framesint自触摸开始以来的帧数(第一帧为 0)
pressurefloat压力(如果支持)
startedbool第一帧为 True
endedbool释放时为 True

所有字段都是只读的。


计数

count = touches.count

或

len(touches)

示例:点击检测

for t in touches:
    if t.started:
        spawn_explosion(t.pos)

注意事项

  • 最大触摸数由引擎定义
  • 安全迭代
  • 索引越界会引发错误