Есть ответ 👍

PyGame не отображает поверхность. Здравствуйте, я начал изучать PyGame и столкнулся с проблемой: холст не отображается в окне. Я ещё новичок в этой теме, возможна ошибка о . Вот код:

import pygame

width = 350

height = 500

FPS = 30

pygame.init()

screen = pygame.display.set_mode((height, width))

pygame.display.set_caption('Title')

clock = pygame.time.Clock()

class Circle(pygame.sprite.Sprite):

def __init__(self):

pygame.sprite.Sprite.__init__(self)

self.image = pygame.Surface((40, 40))

self.rect = self.image.get_rect()

self.rect.x = width - 40

self.rect.y = height - 40

self.speedx = -8

def update(self):

self.rect.x += self.speedx / FPS

if self.rect.centerx == self.image.get_width() - 20:

self.speedx = 0

self.rect.x = 0

circle = Circle()

running = True

while running:

clock.tick(FPS)

# Enter

# Update

for event in pygame.event.get():

if event.type == pygame.QUIT:

running = False

circle.update()

# Painting

screen.fill((0, 0, 0))

pygame.draw.circle(circle.image, (0, 255, 0), (circle.rect.centerx, circle.rect.centery), 20)

screen.blit(circle.image, (circle.image.get_width(), circle.image.get_height()))

pygame.display.flip()

pygame.quit()

P.s. На экране справа налево должен двигаться зелёный круг, у левого края он должен останавливаться.

179
207
Посмотреть ответы 1

Ответы на вопрос:

luda12291
4,4(81 оценок)

привет, программа на фото

Популярно: Информатика