如何创建和绘制视觉滑动手势
我想尝试为 iPhone 项目实现视觉滑动,就像在某些游戏(例如《水果忍者》)中所做的那样。当您在屏幕上拖动手指时,它会留下一条痕迹,一段时间后就会消失。我认为“链”中可以有固定数量的点,并且当新点添加到前面时,旧点会从后面删除。我可以看到使用 -touchesMoved 来生成新点,并使用 NSMutableArray 来跟踪这些点。我只是无法想象我会使用什么方法来实际绘制这些片段。我会制作一个 CALayer 并画一条连接活动点的线吗?或者使用其他一些视图对象并将它们在点处连接在一起......
有什么想法吗?
I'd like to try implementing a visual swipe for an iPhone project, like they do in some games, like Fruit Ninja. As you drag your finger around the screen, it leaves a trail that disappears after a while. I would think that you could have a fixed number of points in the "chain" and as new points are added to the front, old ones are removed from the rear. I can see using -touchesMoved
to generate new points and an NSMutableArray
to keep track of the points. I just can't imaging what method I'd use to actually draw the segments. Would I make one CALayer
and draw a line connecting the active points? Or use some other view object and join them together at the points...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你用 CGPoints 填充“点”,这样的事情就会起作用。警告:这是一项快速剪切、粘贴和编辑工作 - 因此可能会出现错误。另外,我使用 stl::vector 来表示“点”。您可能想使用其他结构。
Something like this would work, if you had populated 'points' with CGPoints. Caveat: this is a quick cut, paste and edit job - so there will probably be errors. Also, I use stl::vector for 'points'. You may want to use some other structure.