返回介绍

Touch.deltaPosition 增量位置

发布于 2019-12-18 15:38:40 字数 2410 浏览 1565 评论 0 收藏 0

JavaScript => public var deltaPosition: Vector2;
C# => public Vector2 deltaPosition;

Description 描述

The position delta since last change.

自最后改变的位置增量。

The absolute position of the touch is recorded periodically and available in the position property. The deltaPosition value is a Vector2 that represents the difference between the touch position recorded on the most recent update and that recorded on the previous update. The deltaTime value gives the time that elapsed between the previous and current updates; you can calculate the touch's speed of motion by dividing deltaPosition.magnitude by deltaTime.

触摸的绝对位置被周期性地记录并在位置属性可用。deltaPosition 的值是个Vector2,表示最近update被记录的位置和上次update记录位置之间的差。该deltaTime值给出了以前和当前的update之间的时间间隔;您可以通过deltaPosition.magnitude除以deltaTime计算运动的触摸的速度。

See Also: deltaTime.

C#:

using UnityEngine;
using System.Collections;
 
public class Sample : MonoBehaviour {
 
	void Update () 
	{
		int nbTouches = Input.touchCount;
 
		if(nbTouches > 0)
		{
			for (int i = 0; i < nbTouches; i++)
			{
				Touch touch = Input.GetTouch(i);
 
				TouchPhase phase = touch.phase;
 
				switch(phase)
				{
				case TouchPhase.Began:
					print("New touch detected at position " + touch.position + " , index " + touch.fingerId);
					break;
				case TouchPhase.Moved:
					print("Touch index " + touch.fingerId + " has moved by " + touch.deltaPosition);
					break;
				case TouchPhase.Stationary:
					print("Touch index " + touch.fingerId + " is stationary at position " + touch.position);
					break;
				case TouchPhase.Ended:
					print("Touch index " + touch.fingerId + " ended at position " + touch.position);
					break;
				case TouchPhase.Canceled:
					print("Touch index " + touch.fingerId + " cancelled");
					break;
				}
			}
		}
	}
}

Touch

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文