鱼C论坛

 找回密码
 立即注册
查看: 1140|回复: 1

pygame.init()

[复制链接]
发表于 2019-7-18 10:40:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import sys

  2. import pygame

  3. def run_game():
  4.     #初始化游戏并创建屏幕对象
  5.     pygame.init()
  6.     screen = pygame.display.set_mode((1200,800))
  7.     pygame.display.set_caption("Alien Invasion")

  8.     #开始主循环
  9.     while True:
  10.         #监视键盘和鼠标事件
  11.         for event in pygame.event.get():
  12.             if event.type == pygame.QUIT:
  13.                 sys.exit()

  14.         #让最近绘制的屏幕可见
  15.         pygame.display.flip()
  16. run_game()      
复制代码

在函数run_game()下面第一行是什么意思?方法init()有什么用?谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-7-18 11:42:44 | 显示全部楼层
初始化所有导入的pygame模块。
官方解释:
  1. Initialize all imported pygame modules. No exceptions will be raised if a module fails, but the total number if successful and failed inits will be returned as a tuple. You can always initialize individual modules manually, but pygame.init()initialize all imported pygame modules is a convenient way to get everything started. The init() functions for individual modules will raise exceptions when they fail.

  2. You may want to initialize the different modules separately to speed up your program or to not use modules your game does not require.

  3. It is safe to call this init() more than once as repeated calls will have no effect. This is true even if you have pygame.quit() all the modules.
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-17 01:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表