如何在 IOS 中平滑地缩放图层以将对象保留在屏幕上?
我正在开发一款游戏,球被击中后可以离开图层的可见区域。我在每一帧中设置球的位置,因为我从 Box2D 获得有关其位置的反馈。当球接近屏幕边缘时,我想缩小适量以保持球可见。有人可以帮助我了解执行此操作的逻辑吗?谢谢。
I'm working on a game where a ball is hit, and can leave the visible area of the layer. I'm setting the position of the ball each frame, as I get feedback from Box2D about its location. When the ball nears the edge of the screen, I want to zoom out just the right amount to keep the ball visible. Can someone give me a hand with the logic to do this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设屏幕大小为 480(像素),球的原始直径为 10 像素。
当球到达距屏幕边缘一定距离时,您会看到一个标志。之后你就得到了你已经知道的速度;这也可以被认为是球向屏幕边缘移动的速率,因此屏幕必须相对于球的尺寸扩展的速率,以确保球行进的总距离包含在屏幕尺寸。
这将演示“缩小”,即球将不断变小,以确保行进的总距离适合屏幕的大小。
Let's have the size of the screen size of 480 (pixels), with the original diameter of the ball being 10 pixels.
You would have a flag for when the ball reaches a certain distance from the edge of the screen. After which you have your velocity, which you already know; this can also be thought of as the rate the ball is moving towards the edge of the screen, therefore the rate at which the screen must expand with respect to the size of the ball to ensure the total distance the ball has travelled is included within the size of the screen.
This will demonstrate a "zoom-out" in that the ball will get continually smaller to ensure that the total distance travelled fits into the size of the screen.