[英]My Program Will Not Draw An Ellipse in Pygame
I'm pretty new to python and pygame and I can't seem to draw a ellipse.我对 python 和 pygame 很陌生,我似乎无法画椭圆。 Please help!
请帮忙!
I'm running this in python3.10.我在 python3.10 中运行它。
Here is all of the source code below.这是下面的所有源代码。
My only suspicion is this code is in python2 cause I used to code in python2 and then I stopped so python3 is new to me.我唯一的怀疑是这段代码在 python2 中,因为我曾经在 python2 中编码,然后我停止了,所以 python3 对我来说是新的。
Whoever fixes it thank you so much!!哪位大神解决一下,万分感谢!!
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)
The ellipse isn't being drawn because you forgot to update the display inside the while
loop.椭圆没有被绘制,因为您忘记更新
while
循环内的显示。 Just type pygame.display.update()
or display.update()
at the bottom of your while
loop in order to do that.只需在
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.