detecting child widgets collision

51 views
Skip to first unread message

George Munyalo

unread,
Jan 17, 2017, 9:32:39 AM1/17/17
to Kivy users support
Is there a way to detect the collision of two child widgets? It seems to me that the collide_widget method only detects collision between the current widget(i.e the current class which is also the parent class/widget) and another specified widget.
Thanks

Andreas Ecker

unread,
Jan 17, 2017, 10:32:03 AM1/17/17
to kivy-...@googlegroups.com

Best would be using the collide_widget method from one of your child widgets.

Checking the implementation of the collide_widget method within kivy/uix/widget.py - it is actually very simple to roll your own method with two widget parameters:

```
        if self.right < wid.x:
            return False
        if self.x > wid.right:
            return False
        if self.top < wid.y:
            return False
        if self.y > wid.top:
            return False
        return True
```


2017-01-17 14:32 GMT+00:00 George Munyalo <gmun...@gmail.com>:
Is there a way to detect the collision of two child widgets? It seems to me that the collide_widget method only detects collision between the current widget(i.e the current class which is also the parent class/widget) and another specified widget.
Thanks

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ZenCODE

unread,
Jan 17, 2017, 12:51:13 PM1/17/17
to Kivy users support

George Munyalo

unread,
Jan 18, 2017, 9:22:27 AM1/18/17
to Kivy users support
Thanks. I was able to achieve this by accessing the child widget instances (self.child1.collide_widget(self.child2))
Reply all
Reply to author
Forward
0 new messages