[英]Rotate sprite in libgdx by following the position of finger on android
我正在嘗試根據手指在觸摸屏上的位置旋轉精靈。
我有一個箭頭,我希望箭頭始終在我在屏幕上拖動時始終指向我的手指。
我可以使用sprite.setRotation(angle)輕松將sprite設置為任意旋轉
我應該怎么做?
非常感謝您能指出我正確的方向。
(ax, ay)
是箭頭中心的坐標, (fx, fy)
是手指的坐標, a
是角度,這是一些偽代碼:
dx = fx - ax
dy = fy - ay
if (dx == 0) {
a = 90
return
}
if (dy == 0) {
a = 0
return
}
//tan(a) == abs(dy) / abs(dx) therefore
a = arctan(dy / dx)
if (dx > 0 && dy > 0) {
// do nothing, a is correct
} else if (dx > 0 && dy < 0) {
a = 360 - a
} else if (dx < 0 && dy > 0) {
a = 180 - a
} else {
a = 180 + a
}
我還沒有實現和測試它,如果需要的話我會在以后做
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.