This is going to be a short exercise. The goal of this section is to develop a primary understanding on use of Pyglet for viewing animations. So let's get on with it.
Download the file
SimpleAnimation.py
from the Packt website. Also download the fileSimpleAnimation.gif
and place it in a sub-directoryimages
. The code is illustrated as follows:1 import pyglet 2 3 animation = pyglet.image.load_animation( 4 "images/SimpleAnimation.gif") 5 6 # Create a sprite object as an instance of this animation. 7 animSprite = pyglet.sprite.Sprite(animation) 8 9 # The main pyglet window with OpenGL context 10 w = animSprite.width 11 h = animSprite.height 12 win = pyglet.window.Window(width=w, height=h) 13 14 # r,g b, color values and transparency for the background 15 r, g, b, alpha = 0.5, 0.5, 0.8, 0.5 16 17 # OpenGL method for setting the background. 18 pyglet.gl.glClearColor(r, g, b, alpha) 19 20 # Draw the sprite in the API method on_draw...