I'm pretty new to python and pygame and I can't seem to draw a ellipse. Please help!
I'm running this in 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.
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. Just type pygame.display.update()
or display.update()
at the bottom of your while
loop in order to do that.
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.