2d游戏开发学习笔记(3)——基于pygame的小游戏开发
- 一.pygame基础知识 pygame有大量可以被独立使用的模块。 pygam.display-显示模块 pygame.keyboard-键盘模块 pygame.mouse-鼠标模块 二.pygame基础测试 1.首先安装pygame,打开cmd使用pip安装pygame: pip install pygame 2.在pycharm中导入pygame模块 3.设置窗口大小和窗口名称 参考代码如下: import pygame from pygame.locals import * import sys def hello_world(): pygame.init() pygame.display.set_mode((640,480)) pygame.display.set_caption("hello world") while True: for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit() pygame.display.update() if __name__=="__main__": hello_world() 运行效果如图: 精灵的使用 介绍: Pygame 提供了两个类 pygame.sprite.Sprite —— 存储 图像数据 image 和 位置 rect