Lets create a simple animation of a 'bouncing ball'. We will use a single image file, ball.png
, which can be downloaded from the Packt website. The dimensions of this image in pixels are 200x200, created on a transparent background. The following screenshot shows this image opened in GIMP image editor. The three dots on the ball identify its side. We will see why this is needed. Imagine this as a ball used in a bowling game.
The image of a ball opened in GIMP appears as shown in the preceding image. The ball size in pixels is 200x200.
Download the files
SingleImageAnimation.py
andball.png
from the Packt website. Place theball.png
file in a sub-directory 'images
' within the directory in whichSingleImageAnimation.py
is saved.The following code snippet shows the overall structure of the code.
1 import pyglet 2 import time 3 4 class SingleImageAnimation(pyglet.window.Window): 5 def __init__(self, width=600, height=600): 6 pass 7 def createDrawableObjects...