微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我运行代码时,图像不可见但是当我将鼠标悬停在任务栏中时,它有图像请帮帮我

如何解决当我运行代码时,图像不可见但是当我将鼠标悬停在任务栏中时,它有图像请帮帮我

当我运行代码时,我的图像没有显示出来。它没有给出任何错误,但是当我将鼠标悬停在我从任务栏创建的新页面中时,我可以看到图像闪烁一秒钟,然后它不会再次停留在主页上。怎么了?请帮帮我。

import pygame

class Ship:
  """A class to manage the ship."""
  
  def __init__(self,ai_game):
    """Initialize the ship and set its starting position."""
    self.screen = ai_game.screen
    self.screen_rect = ai_game.screen.get_rect()
    
    #Load the ship image and get its rect.
    self.image = pygame.image.load('images/ship.bmp')
    self.rect = self.image.get_rect
    
    #Start each new ship at the bottom center of the screen.
    self.rect.midbottom = self.screen_rect.midbottom
    
  def blitme(self):
    """Draw the ship at it's current location."""
    self.screen.blit(self.image,self.rect)

我的主文件

import sys
import pygame
from setting import Settings
from ship import Ship

class AlienInvasion:
  """Overall class to manage game assets and behavIoUr."""
   
  def __init__(self):
    """Initialize the game,and create game resources."""
    
    pygame.init()
    self.screen = Settings()
    self.screen = pygame.display.set_mode(self.settings.screen_width,self.settings.screen_height)
    pygame.display.set_caption("Alien Invasion")
    self.ship = Ship(self)
    
    #set the background color.
    self.bg_color = (230,230,230)
    
  def run_game(self):
    """Start the main loop for the game."""
    
    while True:
      #watch for keyboard and mouse events.
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          sys.exit()
          
      #Redraw the screen during each pass through the loop.
      self.screen.fill(self.settings.bg_color)
      self.ship.blitme()
      
      #make the most recently drawn screen visible.
      pygame.display.flip()
 
if __name__ == '__main__':
  #make a game instance,and run the game.
  ai = AlienInvasion()
  ai.run_game()

我已经检查了我的目录和文件,它们位于正确的位置,一切对我来说似乎都是正确的,但代码仍然无法正常工作。

我的目录看起来像;

PycharmProjects:
    alien invasion:
        images:
            ship.bmp
        alien_invasion.py
        setting.py
        ship.py

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。