游戏中滚动和缩放
我正在开发一款安卓游戏。我有一个活动,它有一个自定义类,可以扩展视图并在其中绘制所有内容。一切工作正常,我已经实现了一种绘制关卡的方法,看起来不错。
我遇到的问题是,对于一个屏幕来说,关卡显然太大了,重新设计它们不是一个选择,因为它会影响用户体验。我看到的唯一解决方案是使屏幕可滚动,以便您可以在渲染的内容周围移动和缩放。我正在寻找的是双击任意位置来放大和缩小并滚动以在地图上移动。
我需要帮助的是如何做到这一点。我知道如何检测用户已滚动或双击,但我不知道应该做什么来实际放大、缩小和滚动(如果检测到滚动)。
我一直在环顾四周,看到一些非常简单的教程,但它们都涉及放大/缩小图像,这不是我需要的。我的关卡是使用许多不同的位图渲染的,因此我知道在更新屏幕(缩放或滚动)时需要重新绘制所有位图。
我的情况和只有一张图像一样吗?当谈到滚动时,我认为需要做的是计算屏幕“移动”了多少,然后更新并使用新的缩放坐标重新绘制视图位图,这是正确的吗?缩放怎么样?
任何帮助将不胜感激。谢谢
I'm in the process of developing an android game. I have an activity that has a custom class that extends the view and where everything is drawn. Everything works fine and I have implemented a way to draw levels and it looks good.
The problem that I have is that the levels are clearly too big for just 1 screen and re-designing them is not an option as it affects the user experience. The only solution that I see is making the screen scrollable so that you can move around the rendered stuff and zooming. What I'm looking for is double tapping anywhere to zoom in and out and scrolling to move around the map.
What I need help with is how to do this. I know how to detect that the user has scrolled or double tapped but I don't know what I should do to actually zoom in and out and scroll (if a scroll is detected).
I have been looking around and saw some very simple tutorials but all of them deal with zooming in/out of an image which is not what I need. My level is rendered using many different bitmaps so I know I need to redraw all of them when updating the screen (zoom or scroll).
Is my case the same as having a single image. When it comes to scrolling I think what need to be done is calculating how much the screen is "moved" then update the and redraw the view bitmaps with the new scaled coordinates, is this correct? What about zooming?
Any help would be much appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦您检测到当前所在位置(即缩放级别),缩放应该很容易,
类似的东西应该可以帮助您缩小/放大图像。当缩放级别超过某一级别时,您可以考虑换出比当前渲染的图像更详细的图像。
Zooming should be easy once you have detected where you are currently at (zoom level i.e.)
Something like that should help you zoom out/in on the image. When the zoom levels cross a certain level, you can consider swapping out an image that is more detailed that the one you are currently rendering.