iPhone上第一次触摸位置更改前的延迟

时间:2013-05-03 04:54:20

标签: iphone touch unity3d

我在Unity3D上使用Input.touches[0].position时遇到问题。对不起,如果问题不清楚,我觉得有点难以描述。

当我开始触摸屏幕并且非常缓慢地开始移动我的手指时,Input.touches[0].position返回的位置不会立即改变,我必须移动一点然后它会跳到当前的触摸位置。

这种情况发生在iPhone上,我没有任何其他触摸设备。

以下是一些可测试的代码:

using System;
using UnityEngine;

// attach this to a game object on the scene
public class TestTouch : MonoBehaviour
{
    private void Update()
    {
        if (Input.touchCount == 1)
        {
            // you have to add a GUIText component to the gameobject
            this.guiText.text = "pos: " + Input.touches[0].position;
        }
    }
}

3 个答案:

答案 0 :(得分:0)

我认为您的问题是由早期手势检测过程引起的。我不确定它是否会解决您的问题,但请尝试一下:

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary)
{
    // Do sth.
}

答案 1 :(得分:0)

如果您需要连续触摸位置,请使用:

-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
   if(touches.count>0)
   {
      UITouch *touch = [touches anyObject];
      CGPoint touchPoint = [touch locationInView:self];
      NSLog("Touch position at (%4.2f|%4.2f)",touchPoint.x,touchPoint.y);
   }
}

答案 2 :(得分:0)

最后我忽略了第一个delta,这是位置的第一个变化,这很好地解决了我的问题。