飞机大战,补给模块,图片显示报错???
错误提示:
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
import pygame
from random import *
pygame.init()
pygame.mixer.init()
class Bullet_Supply(pygame.sprite.Sprite):
def __init__(self,bg_size):
pygame.sprite.Sprite.__init__(self)#继承类
self.image = pygame.image.load("image/bullet_supply.png").convert_alpha()
self.rect = self.image.get_rect()
self.width,self.height =bg_size, bg_size
self.rect.left,self.rect.bottom = \
randint(0,self.width-self.rect.width),-100
self.speed = 5
self.active = False #为true的时候,移动,这里的active是指是否下发补给,若为False,补给不存在
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self):
self.active = True
self.rect.left,self.rect.top = \
randint(0,self.width-self.rect.width),-100
class Bomb_Supply(pygame.sprite.Sprite):
def __init__(self,bg_size):
pygame.sprite.Sprite.__init__(self)#继承类
self.image = pygame.image.load("image/bullet_supply.png").convert()
self.rect = self.image.get_rect()
self.width,self.height =bg_size, bg_size
self.rect.left,self.rect.bottom = \
randint(0,self.width-self.rect.width),-100
self.speed = 5
self.active = False #为true的时候,移动
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self):
self.active = True
self.rect.left,self.rect.top = \
randint(0,self.width-self.rect.width),-100
11-19,37-45行缩进错误,导致语句被直接运行,直接运行会报错,需要从在主程序里定义里屏幕后调用才不会出错。
页:
[1]