如何追踪 NSTouches?
我正在开发一款游戏,这是我第一次需要多次触摸才能工作。我注意到 NSSet 中的触摸索引似乎没有任何押韵或理由。它甚至可以在两个触摸仍处于活动状态时翻转。谁能解释一下吗?谁能解释我如何跟踪每次触摸及其动作(因为在索引处请求触摸可能不会返回您认为在那里的触摸)?
I'm building a game and this is the first time where I've needed more than one touch to work. I've noticed that there appears to be no rhyme or reason to the indexing of touches in the NSSet. It can even flip while both touches are still active. Can anyone explain this? And can anyone explain how I can keep track of each touch and it's movements (since asking for the touch at an index may not return the one you thought was there)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSSet 是明确未排序的,如果他们想要对触摸进行排序,他们会将其改为 NSArray。
请参阅 Apple 的 iOS 事件处理指南,了解跟踪多个触摸的说明和示例代码;简而言之,他们建议使用 CFDictionaryRef 键控每个触摸对象的地址来存储您感兴趣的任何属性。
NSSet is explicitly not ordered, if they had intended the touches to be ordered they would have made it an NSArray instead.
See Apple's Event Handling Guide for iOS for instructions and sample code on tracking multiple touches; in short, they recommend using a CFDictionaryRef keyed on the addresses of each touch object to store whichever properties you are interested in.