Book Image

Kivy - Interactive Applications and Games in Python

By : Roberto Ulloa
Book Image

Kivy - Interactive Applications and Games in Python

By: Roberto Ulloa

Overview of this book

Table of Contents (13 chapters)
Kivy – Interactive Applications and Games in Python Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Localizing coordinates – adding stickmen


In the last section, we used the to_parent() method (line 66) to translate the coordinates relative to the DrawingSpace, to its parent. Remember that we were inside DraggableWidget and the coordinates we received were relative to parent (DrawingSpace).

These coordinates are convenient for DraggableWidget because we positioned it in the parent's coordinates. The method allows us to use the coordinates in the parent's collide_point. This is no longer convenient for when we want to check the coordinates on the parent's parent space or when we need to draw something directly on the canvas of a Widget.

Before studying more examples, let's review the theory. You learned that RelativeLayout is very useful because it is simpler to think inside a constraint space to localize our objects. The problems start when we need to translate coordinates to another Widget area. Let's consider the following screenshot of a Kivy program:

The code to generate this example...