Book Image

Kivy Blueprints

Book Image

Kivy Blueprints

Overview of this book

Table of Contents (17 chapters)
Kivy Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Python Ecosystem
Index

Introducing Kivy Bird


Next on our list is the playable character, that is, the biologically improbable Kivy Bird:

Rare species, the Kivy Bird sprite

There will be nothing fancy related to textures this time; in fact, the Bird class will be derived from Kivy's Image widget (kivy.uix.image.Image) to completely avoid doing any clever rendering whatsoever.

In kivybird.kv we need a bare minimum of properties involving the bird image depicted earlier; its initial position and size are given as follows:

Bird:
    id: bird
    pos_hint: {'center_x': 0.3333, 'center_y': 0.6}
    size: (54, 54)
    size_hint: (None, None)
    source: 'bird.png'

This is the initial implementation of the Bird class in Python:

from kivy.uix.image import Image as ImageWidget

class Bird(ImageWidget):
    pass

Yup, it does nothing at all. Soon, we're going to spoil it by adding rudimentary physics and other things, but first we need to lay some groundwork in the application class in order to make the game stateful.

Revised application...