鱼C论坛

 找回密码
 立即注册
查看: 3670|回复: 4

[已解决]python3.6版本使用pygame结果不显示图像

[复制链接]
发表于 2017-3-12 09:30:28 | 显示全部楼层 |阅读模式

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

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

x
代码无误 但是就是不显示图像
  1. import sys

  2. import pygame

  3. from settings import Settings
  4. from ship import Ship
  5. def run_game():
  6.         pygame.init()
  7.         ai_settings = Settings()
  8.         screen = pygame.display.set_mode(
  9.                 (ai_settings.screen_width,ai_settings.screen_height))
  10.         pygame.display.set_caption("Alien Invasion")
  11.         ship = Ship(screen)
  12.         while True:
  13.                 for event in pygame.event.get():
  14.                         if event.type == pygame.QUIT:
  15.                                 sys.exit()
  16.         screen.fill(ai_settings.bg_color)
  17.         ship.blitme()
  18.         pygame.display.flip()
  19. run_game()
复制代码
  1. import pygame

  2. class Ship():
  3.         def __init__(self,screen):
  4.                 self.screen = screen
  5.                 self.image = pygame.image.load('image\ship.png')
  6.                 self.rect = self.image.get_rect()
  7.                 self.screen_rect = screen.get_rect()
  8.                 self.rect.centerx = self.screen_rect.bottom
  9.        
  10.         def blitme(self):
  11.                 self.screen.blit(self.image,self.rect)
复制代码
  1. class Settings():
  2.         def __init__(self):
  3.                 self.screen_width = 1200
  4.                 self.screen_height = 800
  5.                 self.bg_color = (230,230,230)
复制代码

最后输出结果是一个黑底的窗口 而本来应该是灰色背景窗口加上一艘飞船图像的
最佳答案
2017-3-12 10:04:04
本帖最后由 jerryxjr1220 于 2017-3-12 10:05 编辑

你的事件循环呢?
  1. screen.fill(ai_settings.bg_color)
  2. ship.blitme()
  3. pygame.display.flip()
复制代码

这个要在while True里面
不然程序永远在上面的while True里面执行,这3句根本就执行不到
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-3-12 10:04:04 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jerryxjr1220 于 2017-3-12 10:05 编辑

你的事件循环呢?
  1. screen.fill(ai_settings.bg_color)
  2. ship.blitme()
  3. pygame.display.flip()
复制代码

这个要在while True里面
不然程序永远在上面的while True里面执行,这3句根本就执行不到
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2017-3-12 12:02:14 | 显示全部楼层
程序的主循环
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-3-12 19:22:35 | 显示全部楼层
jerryxjr1220 发表于 2017-3-12 10:04
你的事件循环呢?

这个要在while True里面

哦哦 谢谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-3-12 19:23:23 | 显示全部楼层

原来如此 谢谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-2-26 01:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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