如何测量滑动的速度? [英] How do I measure the velocity of a swipe?

查看:100
本文介绍了如何测量滑动的速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个游戏,将使用滑动的力量作为一个可变的用户输入。

I'm developing a game that will use the force of the swipe as a variable user input.

我从文档中读到touchesEnded事件,可以得到allTouches数组,它是从touchesBegan收集的用户触摸列表。从这我计划得到最后两个触摸,以获得滑动的方向。我也会得到touchesBegan和touchesEnded之间的时间间隔,从中我会得到滑动的速度。我将使用方向和速度来计算滑动的力。

I read from the documentation that on the touchesEnded event, I can get the allTouches array which is a list of the user touches collected from touchesBegan. From this I plan to get the last two touches to get the direction of the swipe. I will also get the time interval between touchesBegan and touchesEnded, from which I will get the speed of the swipe. I will use the direction and the speed to calculate the force of the swipe.

我想知道的是:有更好的方法吗?

What I'd like to know is: is there a better way to do this? Is this already encapsulated in a library call somewhere?

提前感谢。

推荐答案

我已经完成了这些线,而只是通过比较 [touch locationInView:self] [touch previousLocationInView:self] / code>在要移动的对象的Class(UIView的子类)的 touchesEnded 中。这将给你一个向量与位置,方向&

I've accomplished something along these lines rather simply by just comparing [touch locationInView:self] to [touch previousLocationInView:self] in touchesEnded of the Class (subclass of UIView) of the object that will be moved. This will give you a vector with location, direction & rough sense of velocity at the moment user released finger from the iPhone.

这篇关于如何测量滑动的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆