Android 向某个方向移动位图
好的,我正在 Android 中开发一款游戏,现在我在屏幕中央绘制了一个位图。我可以使用 Matrix 类将位图左右旋转一定角度。位图是一艘船的图片,因此当用户想要向前移动时,我希望船以船旋转的当前角度移动。关于我应该如何去做这件事有什么想法吗?
Ok so I am working on a game in Android and right now I have a bitmap that I have drawn at the center of the screen. I can rotate the bitmap left and right by certain degrees using the Matrix class. The bitmap is a picture of a ship so when the user wants to move forward, I want the ship to move at the current angle that the ship is rotated at. Any ideas about how I should go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,经过一系列的试验和错误以及一些关于三角函数的阅读,我已经设法解决了我自己的问题。保存船舶当前位置的向量有一个 X 和一个 Y。然后我需要做的是基于船舶的当前旋转计算速度向量,然后将该速度向量添加到位置向量。
旋转以度为单位,因此需要将其转换为弧度。速度也是船舶的实际速度,并应用于每个速度矢量。希望这能帮助有同样问题的人。
Ok well with a bunch of trial and error and some reading up on trig I have managed to solve my own question. The vector that holds the current location of the ship has an X and a Y. What I then need to do, was based on the current rotation of the ship calculate a speed vector and then add that speed vector to the position vector.
The rotation is in degrees so they needed to be converted to radians. Also speed is the actual speed of the ship and is applied to each speed vector. Hope that will help someone having the same problem.