加载任何内容后触摸的滞后/延迟
编写游戏时,我遇到一个问题,即加载任何内容(图像/声音效果)后,触摸屏会出现大量延迟。我点击屏幕,不久之后,该点击就被注册了。这在 iPhone 4 或 iPad 上几乎不会被注意到,但在任何较旧的设备上(特别是 2G 设备),我会在触摸注册之前观察好几秒钟!
为了清楚起见,我点击...然后将手指从屏幕上移开,大约 5 秒后,我点击的图标记录了这次点击。
它似乎只在加载大量图像后才会发生(我在每个级别开始时以及返回前端时执行此操作)。一旦它“赶上”,一切都会恢复正常。
有什么方法可以在加载后刷新触摸缓冲区(我假设必须存在!)?
预先感谢
炖菜
Writing a game, and I'm having an issue whereby after loading anything (images / sound effect), the touchscreen suffers a high amount of latency. I tap the screen, and a short time later, that tap is registered. This is barely noticeable on iPhone 4 or iPad, but on anything older (Particularly 2G devices), I'm looking at a good few seconds before touches register!
To be clear, I tap... then take my finger off the screen, and then about 5 seconds later the icon I clicked on registers the tap.
It only seems to happen after loading a large amount of images (Which I do at the start of each level, and when returning to the frontend). Once it 'catches up' it all works fine again.
Is there any way to flush the touches buffer (I assume one must exist!) after a load?
Thanks in advance
Stew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想做的是“清除缓存”。加载大图像会占用大量内存,众所周知,智能手机内存是一种宝贵的商品……你总是无法获得足够的内存。特别是如果您使用处理堆存储和垃圾收集的运行时语言进行编程。通常,当可用 RAM 无法为所有“缓冲”请求提供足够的可寻址空间时,您会看到这样的行为。您遇到的另一个问题是处理能力和内核……尽管现代手机已经变得相当不错,但与标准计算设备相比,它们仍然很差劲。如果线程用完,应用程序必须等待,直到有一个线程空闲。这也可能导致您遇到的问题......事实上,我敢打赌这就是问题所在。我之前读过一篇论坛帖子,可能会有所帮助:
我们什么时候应该删除 iPhone 应用程序中的缓存数据?
您可以按如下方式清除缓存...但我不确定这是否能解决您的问题。如果您保留这些图像,您打算将它们存储到手机的闪存中吗?请记住,如果您从内存中删除图像,则需要再次将它们恢复。如果我们在这里谈论背景图像,那么减小图像的大小可能是更好的建议...或者加载更大的图像并使用 DIV 跨过它的精灵...。由于我不确定您如何构建“游戏”,我无法推断出最佳选择。
What it sounds like you want to do is "clear you cache". Loading large images eats up a lot of memory and as we all know, smartphone memory is a valuable commodity ... you just can't get enough of it. Especially if you are programming in a runtime language that deals with a heap store and garbage collection. Often times you see the behavior you are getting when the available RAM does not offer enough addressable space for all requests to "buffer". Another issue you have is processing power and cores ... although modern phones are getting pretty good they still pail in comparison to standard computing devices. If you run out of threads the app must wait until one is free. This can also lead to the issue you are having ... in fact, I bet this is the problem. I read a forum post before that might help:
When should we delete the cache data in an iPhone apps?
You can clear the cache as follows ... but I am not sure that will solve your issue. If you are keeping these images around do you intend to store them to the flash memory on the phone? Remember, if you remove the images from memory then you will need to bring them back up again. It may be a better suggestion to reduce the size of the images ... or to load a larger image and sprite across it with DIV's ... if we are talking background images here. As I am not certain how you have architected the "game" I can not infer the best option.