我创建的那个一张图片上下移动和敌机.但是屏幕一直黑.和别人的代码一样到底哪不行
def __create_sprites(self):
bg1 = BackGround()
bg2 = BackGround(True)
bg2.rect.y= -bg2.rect.height
self.back_group = pygame.sprite.Group(bg1,bg2)
self.enemy_group= pygame.sprite.Group
def __event_handler(self):#监听
for event in pygame.event.get():
# 判断是否是点击了退出按钮
if event.type == pygame.QUIT:
PlaneGame.__game_over()
elif event.type==CREATE_ENEMY:
print("敌机出场")
evemy = Enemy()
self.enemy_group.add(1)
def __check_collied(self):#碰撞检测
pass
def __update_sprites(self):#更新精灵
self.back_groud.update()
self.back_groud.draw(self.screen)
self.enemy_group.update()
self.enemy_group.draw(self.screen)
**游戏精灵模块**
import random
import pygame
SCREEN_RECT = pygame.Rect(0,0,400,600)
CREATE_ENEMY=pygame.USEREVENT
class GameSprites(pygame.sprite.Sprite):
"""飞机大战游戏精灵"""
def __init__(self,image_name,speed=1):
super().__init__() #定义父类的初始化方法
self.image = pygame.image.load(image_name)
self.rect = self.image.get_rect() #get_rect设置窗口大小和图片大小一样
self.speed = speed
def update(self, *args):
#在屏幕垂直方向上移动
self.rect.y += self.speed
class BackGround(GameSprites):
"""游戏背景"""
def __init__(self,is_out = False):
pygame.display.set_caption("周彬大战菊花怪")
if is_out:
self.rect.y = -self.rect.y
def update(self, *args):
super().update()
if self.rect.y >= SCREEN_RECT.height:
self.rect.y = -self.rect.height