2
我正在开发一个在Kivy中触摸的游戏中获取对象时遇到了一些问题。这是我到目前为止的代码:使对象旋转并在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]
我要的是,当用户触摸(并保持画面),在“玩家”不断旋转,以匹配触摸的位置,并逐步走向移动触摸屏。建议? 我会继续工作,让你知道我使用什么。
由于提前, Ilmiont
编辑: 发布以来,我尝试这样做,它的效果要好得多......但对象停止从光标移动往往是几个像素,到一边。我希望它停止,所以光标应该直接在上面...即玩家在移动设备上的手指将握住它。
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)
当你说“不断旋转以匹配触摸的位置”时,你的意思是玩家旋转以面对触摸位置? “持续”是什么意思? – 2014-08-29 15:59:45
是的,“旋转以面对接触的位置”。尽管如此,请参阅我的编辑,但这种作品不是但似乎相当不稳定和不准确。 – Ilmiont 2014-08-29 16:01:23