[英]Python Kivy. Negative values
你好,我有一个问题,我正在用 Python 在 Kivy 库中制作一个游戏。 我想在函数“ on_touch_down ”中反转 self.hero_pos.points 我知道如何通过从 update_hero 复制粘贴坐标并使它们为负数来实现。 但我很好奇我可以用更简单的方式来保持代码干燥吗? :)
def on_touch_down(self, touch):
#what should i do?
def on_touch_up(self,touch):
pass
def init_hero(self):
with self.canvas:
Color(0,1,0)
self.hero_pos = Triangle()
def update_hero(self):
center_x = int(self.width/2)
spacing = self.V_spacing * self.width
ymax = self.height * self.hero_height
ymin = self.height * self.hero_height
x1, y1 = (center_x - spacing*.25, ymin)
x2, y2 = (center_x - spacing *.5, ymax + ymin)
x3, y3 = ( center_x - spacing*.75, ymin)
self.hero_pos.points = [ x1,y1,x2,y2,x3,y3]
再会。 我不确定“反向”是什么意思。
def reverse(self):
n_points = len(self.hero_pos.points)//2
ans = []
for r in range(1, n_points, 2):
ans.append(self.hero_pos.points[r-1])
ans.append(self.hero_pos.points[r])
return ans
def reverse(self): n_points = len(self.hero_pos.points)//2 ans = [] for r in range(1, n_points, 2): ans.append(self.hero_pos.points[r-1]) ans.append(self.hero_pos.points[r]) return ans
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.