Xenko基础API笔记3- Pointers指针设备屏幕上点对应的手指触摸。

时间:2020-12-23 06:44:26

样本
这里是一个简单的示例程序,跟踪目前在屏幕上的指针和打印他们的位置。访问输入字段,类继承自@ SiliconStudio.Xenko。脚本的类。

 public override async Task Execute()
{
var pointerPositions = new Dictionary<int, Vector2>();
while (true)
{
await Scheduler.NextFrame();
foreach (var pointerEvent in Input.PointerEvents)
{
switch (pointerEvent.State)
{
case PointerState.Down:
pointerPositions[pointerEvent.PointerId] = pointerEvent.Position;
break;
case PointerState.Move:
pointerPositions[pointerEvent.PointerId] = pointerEvent.Position;
break;
case PointerState.Up:
case PointerState.Out:
case PointerState.Cancel:
pointerPositions.Remove(pointerEvent.PointerId);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
var positionsStr = pointerPositions.Values.Aggregate("", (current, pointer) => current + (pointer.ToString() + ", "));
logger.Info("There are currently {0} pointers on the screen located at {1}", pointerPositions.Count, positionsStr);
}
}

Remarks

  • A pointer event contains information on only one pointer. If several pointers are modified simultaneously one pointer event is sent for each of them.
  • Pointer events are listed by chronological order (time of the event).
  • A series of pointer event for a given pointer always starts by a Down action then followed by 0 or more Move actions and ends by an Up, Out or Cancel action.
  • Pointer positions are normalized. (0,0) represents the left-top corner of the screen and (1,1) represents the right-bottom corner of the screen.
  • The association finger <-> pointer ID is valid only during an Down->Move->Up sequence of pointer events. So a given finger can have different IDs each time it leaves the screen.
  • Pointer events' delta-values (e.g. DeltaTime and DeltaPosition) represent the changes since the last event of the same pointer (same pointer ID). Delta values are always nulls at the beginning a given pointer series of event (e.g. when the pointer state is Down).

讲话
一个指针事件包含的信息只有一个指针。如果同时有几个指针修改一个指针事件发送。
指针事件按时间顺序列出事件的(时间)。
一系列的指针事件对于一个给定的指针总是首先行动然后其次是0或多个移动操作和结束的,或取消行动。
指针位置都是标准化的。(0,0)代表工具屏幕的角落,(1,1)代表right-bottom屏幕的角落。
协会手指< - >指针ID是有效的只有在下降- > - >移动指针的事件序列。因此给定的手指可以有不同的id每次离开屏幕。
指针事件的增量值(例如DeltaTime和DeltaPosition)代表相同的变化自从上次事件指针(相同的指针ID)。δ值总是在一开始给定null指针一系列事件(例如当指针状态)。