如何在 Android 和 Android 上实现相同的投掷结果iPhone
我将一款游戏从 iPhone 移植到 Android 上。全部基于 OpenGL,并且滚动计算完全相同。我注意到,在 iPhone 上滚动游戏时,我可以更快地滚动,并且抬起手指时的启动速度感觉与手指移动时的速度相同。
然而不幸的是,在 Android 设备上,这并不相同。当我在滚动时抬起手指时,开始滚动速度感觉更慢。在 iPhone 上滚动感觉更准确。
Android 处理触摸的方式与 iPhone 有何不同?我如何利用这一点来实现与 iPhone 类似的感觉。在 Android 上,所有应用程序在滑动时,我抬起手指的速度与我手指移动的速度感觉不一样。
I ported a game from iPhone to android. All OpenGL based, and exactly the same calculations for scrolling. I noticed that on the iPhone when scrolling through the game I can scroll faster, and the starting speed as I lifted my finger felt the same as my finger was moving.
However on the android device unfortunatly this was wan not the same. As I lifter my finger when scrolling, the start scroll speed felt slower. Scrolling on the iPhone feels more accurate.
Is there anything special about how the android handles the touches that is differnt than the iPhone? and how can I take advantage of this to achieve a similar feeling as on the iPhone. On the On Android all applications when flinging the speed that I have lifted my finger from doesn't feel the same as how fast my finger moved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了。对于相同(或接近)的位置,android 会给出一个 ACTION_MOVE,然后给出一个 ACTION_UP。 iPhone 根本不这样做!它只是给出了一个触摸结束!因此,如果有运动,我在 Android 上至少会有 3 个点,但在 iPhone 上有 2 个点(触地、在不同位置触摸)
接下来的事情是 ACTION_MOVE 和 ACTION_UP 不会立即发生,以及计算采样点平均速度时的显着时间间隔。
解决方案:在ACTION_UP上,如果有ACTION_MOVE,则滑动存储的所有秒数,以便ACTION_MOVE在ACTION_UP发生时“发生”。不要将最后的修饰点纳入速度计算中。现在像往常一样计算速度。
摘要
在 Android 上,如果您移动了手指,您会在 ACTION_UP 之前收到 ACTION_MOVE。并且 ACTION_UP 与 ACTION_MOVE 大致处于相同位置,使得结束时的速度看起来大约为 0。iPhone 不会这样做,iPhone 不会为最后一次 TouchEnded 提供 TouchMoved(IE 按下,移动手指,抬起) ,如果您在 iPhone 上执行得足够快,您将不会获得 TouchMoved 手指的中间事件,而在 Android 上则如此)。
Android / iPhone 等效的
另外我注意到 Android 上有一些点历史功能。我没有使用那些。我将触摸和时间戳存储在我自己的数组中。
I found it. The android gives a ACTION_MOVE then a ACTION_UP for the same (or close) location. iPhone doesn't do this at all! It just gives a touchesEnded! So if there is motion I will at minimum have 3 points on the android ALWAYS, But on the iPhone its 2 points (touch down, touch up both at different locations)
The next thing is the ACTION_MOVE AND ACTION_UP don't happen right away, and its significant time interval when calculating the average speed of sampled points.
Solution: On ACTION_UP, if there is a ACTION_MOVE slide all the seconds stored so that the ACTION_MOVE "happens" when the ACTION_UP occured. Don't put the final touches up point in the speed calculation. And now calculate speed as usual.
Summary
On Android if you have moved your finger you get a ACTION_MOVE before a ACTION_UP. And ACTION_UP is roughly at the same location at the ACTION_MOVE making it seem as if the speed at the end is roughly 0. iPhone does not do this, iPhone does not give a touchesMoved for the last touchesEnded (IE touch down, move finger, lift, if you do it fast enough on iPhone you wont get the intermediate event for touchesMoved your finger, where as on the android you do).
Android / iPhone equivalent's
Also I noticed on Android there is some point history functions. I did not use those. I stored touches and there timestamps in my own array.
您是否考虑了屏幕的 dpi 或屏幕分辨率,以每秒点数或每秒像素数进行滑动?这很容易影响事情。
另外,是的,android的触摸处理似乎有点慢。您也许可以添加一定量的“捏造因素”以获得更接近的响应(也许 +10% 或类似的值)。但话虽如此,Android 应用程序的“滑动”速度是触摸屏和框架的特定数学计算的组合,用于确定滑动速度和衰减率 - 因此,就除您的应用程序之外的应用程序而言,您可能只是看到了很多不同两个平台之间的数学/方法。
Are you taking into account the dpi of the screen, or resolution of the screen, to either do your flings in dots-per-second or in px-per-second? That could easily affect things.
In addition, yes, android's touch processing seems to be a bit slower. You might be able to add a 'fudge factor' of some amount to get a closer response (maybe +10% or something like that). But that said, the 'flinging' speed of android apps is a combination of touchscreen and the framework's particular math calcs for determining fling speed and rate of decay -- so in terms of apps OTHER than yours, you could just simply be seeing much different math/approaches between the two platforms.