当我触按MyPaintWidget
时,一个椭圆在它的canvas
中被创建。
但是我还想检测用户何时接触到已经绘制的椭圆,这样我就可以执行其他指令,而不是再次绘制椭圆。
我看到self.collide_point
只对Widget
有效
有别的解决办法吗?你知道吗
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse
class MyPaintWidget(Widget):
def on_touch_down(self,touch):
with self.canvas:
Color(1,1,0)
d=30
Ellipse(pos=(touch.x-d/2,touch.y-d/2),size=(d,d))
class MyPaintApp(App):
def build(self):
return MyPaintWidget()
if __name__=='__main__':
MyPaintApp().run()
您可以将椭圆的中心和半径存储在
ListProperty
的MyPaintWidget
中。在on_touch_down
中,您可以检查是否与任何椭圆发生碰撞,并绘制另一个椭圆或执行其他操作。在下面的示例中,我添加了第二个半径来显示一般解决方案。你知道吗相关问题 更多 >
编程相关推荐