[英]My Program Will Not Draw An Ellipse in Pygame
我對 python 和 pygame 很陌生,我似乎無法畫橢圓。 請幫忙!
我在 python3.10 中運行它。
這是下面的所有源代碼。
我唯一的懷疑是這段代碼在 python2 中,因為我曾經在 python2 中編碼,然后我停止了,所以 python3 對我來說是新的。
哪位大神解決一下,萬分感謝!!
from pygame import *
import pygame
init()
S0 = 640
S1 = 480
screen = display.set_mode((S0, S1))
display.set_caption("Zero-Player-Game")
clock = pygame.time.Clock()
x = 10
y = 10
dx = 1
dy = 2
Black = (0, 0, 0)
White = (255, 255, 255)
p_size = 50
end = False
while not end:
for e in event.get():
if e.type == QUIT:
end = True
x += dx
y += dy
if y < 0 or y > S1 - p_size:
dy *= -1
if x < 0 or x > S0 - p_size:
dx *= -1
screen.fill(Black)
draw.ellipse(screen, White, (x, y, p_size, p_size))
clock.tick(100)
橢圓沒有被繪制,因為您忘記更新while
循環內的顯示。 只需在while
循環底部鍵入pygame.display.update()
或display.update()
即可。
from pygame import *
import pygame
init()
S0 = 640
S1 = 480
screen = display.set_mode((S0, S1))
display.set_caption("Zero-Player-Game")
clock = pygame.time.Clock()
x = 10
y = 10
dx = 1
dy = 2
Black = (0, 0, 0)
White = (255, 255, 255)
p_size = 50
end = False
while not end:
for e in event.get():
if e.type == QUIT:
end = True
x += dx
y += dy
if y < 0 or y > S1 - p_size:
dy *= -1
if x < 0 or x > S0 - p_size:
dx *= -1
screen.fill(Black)
draw.ellipse(screen, White, (x, y, p_size, p_size))
clock.tick(100)
pygame.display.update()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.