Let's create an animation of falling raindrops by using different regions of a single image.
Download the Python source file
RainDropsAnimation.py
and the image filedroplet.png
from the Packt website. As done before, place the image file in a sub-directoryimages
. Theimages
directory should be placed in the directory in which the Python source file is located.The
__init__
method of the classRainDropsAnimation
is presented.1 def __init__(self, width=None, height=None): 2 pyglet.window.Window.__init__(self, 3 width=width, 4 height=height) 5 self.drawableObjects = [] 6 self.createDrawableObjects()
The code is self-explanatory. The class
RainDropsAnimation
inheritspyglet.window.Window
. The constructor of the class calls the method that creates theSprite
instance for displaying the animation on the screen.Let's review the
createDrawableObjects
method.1 def createDrawableObjects(self): 2 num_rows = 4 3 num_columns...