鱼C论坛

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

[已解决]飞机大战,补给模块,图片显示报错???

[复制链接]
发表于 2020-5-18 12:12:05 | 显示全部楼层 |阅读模式

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

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

x

错误提示:
File "C:/Users/Administrator/Desktop/python/3.飞机大战素材 代码--小甲鱼/supply.py", line 10, in Bullet_Supply
    self.image = pygame.image.load("image/bullet_supply.png").convert_alpha()
pygame.error: No video mode has been set

我懵了,哪来的video

  1. import pygame
  2. from random import *

  3. pygame.init()
  4. pygame.mixer.init()
  5. class Bullet_Supply(pygame.sprite.Sprite):
  6.     def __init__(self,bg_size):
  7.         pygame.sprite.Sprite.__init__(self)  #继承类

  8.     self.image = pygame.image.load("image/bullet_supply.png").convert_alpha()
  9.     self.rect = self.image.get_rect()
  10.     self.width,self.height =bg_size[0], bg_size[1]
  11.     self.rect.left,self.rect.bottom = \
  12.                                      randint(0,self.width-self.rect.width),-100
  13.                                     
  14.     self.speed = 5
  15.     self.active = False    #为true的时候,移动,这里的active是指是否下发补给,若为False,补给不存在
  16.     self.mask = pygame.mask.from_surface(self.image)
  17.    
  18.     def move(self):
  19.         if self.rect.top < self.height:
  20.             self.rect.top += self.speed
  21.         else:
  22.             self.active = False

  23.    
  24.     def reset(self):
  25.         self.active = True     
  26.         self.rect.left,self.rect.top = \
  27.                                      randint(0,self.width-self.rect.width),-100

  28. class Bomb_Supply(pygame.sprite.Sprite):
  29.     def __init__(self,bg_size):
  30.         pygame.sprite.Sprite.__init__(self)  #继承类

  31.     self.image = pygame.image.load("image/bullet_supply.png").convert()
  32.     self.rect = self.image.get_rect()
  33.     self.width,self.height =bg_size[0], bg_size[1]
  34.     self.rect.left,self.rect.bottom = \
  35.                                      randint(0,self.width-self.rect.width),-100
  36.                                     
  37.     self.speed = 5
  38.     self.active = False    #为true的时候,移动
  39.     self.mask = pygame.mask.from_surface(self.image)
  40.    
  41.     def move(self):
  42.         if self.rect.top < self.height:
  43.             self.rect.top += self.speed
  44.         else:
  45.             self.active = False

  46.    
  47.     def reset(self):
  48.         self.active = True     
  49.         self.rect.left,self.rect.top = \
  50.                                      randint(0,self.width-self.rect.width),-100
复制代码
最佳答案
2020-5-18 13:23:58
11-19,37-45行缩进错误,导致语句被直接运行,直接运行会报错,需要从在主程序里定义里屏幕后调用才不会出错。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-5-18 13:23:58 | 显示全部楼层    本楼为最佳答案   
11-19,37-45行缩进错误,导致语句被直接运行,直接运行会报错,需要从在主程序里定义里屏幕后调用才不会出错。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-19 16:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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