【发布时间】:2014-08-29 15:53:07
【问题描述】:
在我正在开发的游戏中,我在获取对象时遇到了一些麻烦,以便在 Kivy 中进行触摸。到目前为止,这是我的代码:
class Player(Widget):
angle = NumericProperty(0)
def on_touch_move(self, touch):
y = (touch.y - self.center[1])
x = (touch.x - self.center[0])
calc = math.degrees(math.atan2(y, x))
new_angle = calc if calc > 0 else 360+calc
self.angle = new_angle
self.pos = [touch.x - 50, touch.y - 50]
我想要的是,当用户触摸(并握住屏幕)时,“播放器”会不断旋转以匹配触摸的位置并逐渐向触摸移动。建议? 我会继续努力,让你知道我用的是什么。
提前致谢, 伊尔蒙
编辑: 自发布以来,我已经尝试过这个并且效果更好......但是对象经常停止从光标向侧面移动几个像素。我希望它停止,因此光标应该直接位于上方……即移动设备上的玩家手指会握住它。
def on_touch_move(self, touch):
y = (touch.y - self.center[1])
x = (touch.x - self.center[0])
calc = math.degrees(math.atan2(y, x))
new_angle = calc if calc > 0 else 360+calc
self.angle = new_angle
anim = Animation(x = touch.x, y = touch.y)
anim.start(self)
【问题讨论】:
-
当您说“不断旋转以匹配触摸的位置”时,您的意思是玩家旋转以面对触摸的位置吗? “持续”是什么意思?
-
是的,“旋转以面对触摸的位置”。不过请看我的编辑,这有点不起作用,但它似乎相当不稳定和不准确。
标签: python animation rotation kivy