Stack Overflow на русском Asked on February 6, 2021
Подскажите, как побороть. При запуске приложения, вместо background отображается черное окно. При закрытие приложения, на пол секунды появляется background
import pygame
pygame.init()
x = 6
y = 440
width = 50
height = 37
speed = 5
isJump = False
jumpCount = 10
left = False
right = False
animationCount = 0
window = pygame.display.set_mode((512, 256))
pygame.display.set_caption('Firts Game')
clock = pygame.time.Clock()
walkRight = [pygame.image.load('assets\player-run-right-01.png'),
pygame.image.load('assets\player-run-right-02.png'), pygame.image.load('assets\player-run-right-03.png'),
pygame.image.load('assets\player-run-right-04.png'), pygame.image.load('assets\player-run-right-05.png')]
walkLeft = [pygame.image.load('assets\player-run-left-01.png'),
pygame.image.load('assets\player-run-left-02.png'), pygame.image.load('assets\player-run-left-03.png'),
pygame.image.load('assets\player-run-left-04.png'), pygame.image.load('assets\player-run-left-05.png')]
background = pygame.image.load('assets\background.png')
playerStand = pygame.image.load('assets\adventurer-idle-03.png')
def drawWindow():
global animationCount
window.blit(background, (0, 0))
if animationCount >= 25:
animationCount = 0
if left:
window.blit(walkLeft[animationCount // 5], (x, y))
animationCount += 1
elif right:
window.blit(walkRight[animationCount // 5], (x, y))
animationCount += 1
else:
window.blit(playerStand, (x, y))
pygame.display.update()
run = True
while run:
clock.tick(25)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x > 5:
x -= speed
left = True
right = False
elif keys[pygame.K_RIGHT] and x < 500 - width - 5:
x += speed
left = False
right = True
else:
left = False
right = False
animationCount = 0
if not(isJump):
if keys[pygame.K_SPACE]:
isJump = True
else:
if jumpCount >= -10:
y -= jumpCount * 2
jumpCount -= 1
else:
isJump = False
jumpCount = 10
drawWindow()
pygame.quit()
Разобрался. Функция drawWindow() должна выполнятся из цикла while
Answered by Vadim on February 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP