滚动视图和 Cocos2D
我正在尝试在 Cocos2D 中开发一个可滚动的图块地图,它使用 UIPanGestureRecognizer
来完成肮脏的工作,但是在开发它的过程中,偶然发现了一些我想要的问题寻求建议。
基本的滚动管理工作正常,它精确且准确,并且通过将平移手势管理器识别的翻译添加到地图的图块来工作。问题是地图很大,我只画了它的一个小视口,而我想管理它,就像它可以滚动一样,没有任何问题。
我在想的是,一旦整行或整列离开可见屏幕,它就会移动到另一侧,相应的纹理矩形就会更新(我完全使用CCSpriteBatchNode< /code>),这样它将不断更新视口以使整个事情正常工作。这看起来不错,但我在处理何时移动行/列、如何跟踪这个问题(例如,当平移从前到后改变方向时)以及许多小细节方面发现了许多问题,这让我认为我应该找到更好的方法。
我的问题有通用的解决方案吗?也就是说:管理瓦片地图的可滚动视口,该视口应该在整个地图上移动,这样对于最终用户来说,地图看起来就像是无限的。
提前致谢
I'm trying to develop a scrollable tile map in Cocos2D which uses an UIPanGestureRecognizer
to do the dirty work, but while developing it, stumbled upon some problems for which I would like to ask for an advice.
The basic scrolling management works fine, it's precise and accurate and works by adding the translation recognized by the pan gesture manager to the tiles of the map. The problem is that the map is large and I just draw a small viewport of it, while I want to manage it like it's scrollable without any problem.
What I was thinking about is that, as soon as a whole row or column get out of the visible screen, it is moved to the opposite side, the corresponding texture rects are updated (I'm working entirely with a CCSpriteBatchNode
), so that it will continuously update the viewport to make the whole thing work. This seems fine but I've found many problems in dealing with when to move the row/column, how to keep track of this issue (eg when pan changes direction from forth to back) and many little details which make me think that I should find a better approach.
Is there a common solution to my problem? That is: managing a scrollable viewport of a tilemap which should move over the whole map so the to the end user it seems like as if the map is infinite.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过开发一个视口解决了我的问题,其中行和列有效地从左侧移动到右侧,从顶部移动到底部。
当新的列或行进入视口时,这是自动完成的,并且是通过将绘制的视口扩展到实际视口上,其扩展量足以避免用户出现任何图形问题。
I solved my issue by developing a viewport in which rows and columns are effectively moved from left side to right side and from top side to bottom side.
This is done automatically when a new column or row enters the viewport and it's made by expanding the drawn viewport over the real one by an amount which is enough to avoid any graphical issue to the user.