1 说明:
1.1 安装
pip install pyglet
1.2 相关地址
https://pypi.org/project/pyglet/http://pyglet.org/https://github.com/pyglet/pyglet
1.3 介绍
1.3.1 是python的游戏三大库之一,适合游戏动画,1D,2D,3D设计。
1.3.2 一个python下的多媒体框架,属于轻量级别,可以轻易的做出交互丰富的应用。比pygame,panda3d更容易学习和掌握。
2 2d动画散步的精灵。
2.1 代码:dinosaur.py
#网上gif下载地址# The dinosaur.gif file packaged alongside this script is in the public# domain, it was obtained from http://www.gifanimations.com/.#导入模块import sysimport pyglet##定义系统加载图片地址if len(sys.argv) > 1: # Load the animation from file path. animation = pyglet.image.load_animation(sys.argv[1]) texture_bin = pyglet.image.atlas.TextureBin() animation.add_to_texture_bin(texture_bin)else: # 文件与py文件在同一个目录,这是pyglet的特色之处 animation = pyglet.resource.animation('dinosaur.gif')#定义精灵=sprite和导出精灵模块sprite = pyglet.sprite.Sprite(animation)#定义窗口和大小window = pyglet.window.Window( #窗口标题名caption='散步的精灵动画',#窗口大小可调节resizable=True,width=8*sprite.width, height=8*sprite.height)# Set window background color to white.# 设置窗口背景颜色为白色pyglet.gl.glClearColor(1, 1, 1, 1) #默认背景颜色是黑色,注释掉就是黑色#window的装饰器法@window.eventdef on_draw(): wi