带有碰撞检测的动画?
我无法找出使用碰撞检测设置动画的最佳方法。我有一个功能齐全的 Falldown 版本(流行的计算器游戏),使用处理程序和 onDraw() 为行和位图球绘制矩形。但是,该动画会跳过(看起来很滞后),因此我尝试将动画切换为补间动画。
我的问题是一个概念性问题:如何检测动画中间的碰撞?我认为横向动画采用两条路线之一: a) 我以非常小的步骤制作动画。然而,我想这看起来和当前的动画设置一样糟糕。 b) 我将动画一直设置到屏幕的左侧或右侧,但动画中的每一步都会检查以确保球不会穿过一行。
我在球向下运动时面临类似的问题。是否可以不断访问/更新球的位置(存储为整数),然后在球与物体碰撞时缩短动画?当且仅当球不在行的一部分之上时,是否可以让球向下运动?必须有某种方法来检测动画内部的碰撞,但我不知道如何。
编辑:如果动画类不适合游戏,我应该如何为我的游戏制作动画?就像我说的,即使我将延迟设置为 1 毫秒,我的处理程序 ondraw 系统也会使球跳来跳去。
I am having trouble figuring out the best way to set up animation with collision detection. I have a fully functional version of falldown (the popular calculator game), using a handler and onDraw() to draw rectangles for the rows and a bitmap ball. However, this animation skips (looks laggy) and so I am trying to switch the animation over to a tween animation.
My question is a conceptual one: how do i detect collisions in the middle of an animation? I see the sideways animation as taking one of two routes:
a) I animate in very small steps. However, I imagine this would look just as bad as the current animation set-up.
b) I set an animation all the way to the left or right of the screen, but every step in the animation checks to make sure the ball is not going through a row.
I face a similar problem with the downward motion of the ball. Is it possible to constantly access/update the position of the ball (stored as an integer) and then cut the animation short if it is colliding with something? Is it possible to have the ball animate downward if and only if it is not above a piece of the row? There must be some way to detect collisions inside of the animation but I don't know how.
edit: if the animation class isn't suitable for games, how am I supposed to animate my game? Like I said, the handler-ondraw system I have makes the ball skip around, even when i set the delay to 1 millisecond.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个线程用于 UI 画布绘制方法,一个线程用于游戏逻辑/任何非 UI 相关的内容。
一个线程更新对象位置等...而另一个 UI 线程只是将它们绘制到屏幕上。
在这个庄园中,您的游戏逻辑线程是连续的,并且在每条路径上都会更新 X、Y 位置并处理碰撞检测等内容...绘制线程仅采用这些更新的 X、Y 位置并将位图绘制到画布上。
您可以使用 SurfaceView 作为画布来绘制位图/图像/精灵集合。您可以查看 Google 提供的大量 Android 游戏示例,快速了解这是如何完成的,但通常就是我上面描述的方式。
One thread for UI canvas draw methods and one thread for Game Logic / Anything non UI related.
One thread updates objects positions etc... and the other UI thread just draws them onto the screen.
In this manor your game logic thread is continuous and on every path updates X,Y positions and handles things like collision detection etc... The draw thread just takes those updated X,Y positions and draws bitmaps onto a canvas.
You can use the SurfaceView as the canvas on which to draw the collection of bitmaps/image/sprites. You can look at the numerous Android Game examples provided by Google for a quick and dirty look at how this is accomplished but it is generally how I described above.