Я пытаюсь использовать pygame для рисования карты на экране, но не могу понять, почему это не так. Я не получаю трассировку. Экран инициализируется, затем изображение не рисуется. Я пытался с другими изображениями .bmp с тем же результатом, поэтому в моем коде должно быть что-то, что не упорядочено/не правильно написано.
Вот основной модуль игры:
import pygame
import sys
from board import Board
def run_game():
#Launch the screen.
screen_size = (1200, 700)
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption('Horde')
#Draw the board.
game_board = Board(screen)
game_board.blit_board()
#Body of the game.
flag = True
while flag == True:
game_board.update_board()
run_game()
Вот модуль платы, который вы видите используемым. В частности, функция blit_board()
, которая молча не может отрисовать файл map.bmp
, который я прошу (файл находится в том же каталоге).
import pygame
import sys
class Board():
def __init__(self, screen):
"""Initialize the board and set its starting position"""
self.screen = screen
#Load the board image and get its rect.
self.image = pygame.image.load('coll.bmp')
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
#Start the board image at the center of the screen.
self.rect.centerx = self.screen_rect.centerx
self.rect.centery = self.screen_rect.centery
def blit_board(self):
"""Draw the board on the screen."""
self.screen.blit(self.image, self.rect)
def update_board(self):
"""Updates the map, however and whenever needed."""
#Listens for the user to click the 'x' to exit.
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
#Re-draws the map.
self.blit_board()
Все, что я получаю, это черный экран. Почему изображение map.bmp
не отрисовывается?
pygame.display.flip()
илиpygame.display.update()
после блита для фактического обновления экрана? - person Dan Mašek   schedule 19.04.2016