Hi I'm very new at Python and now I am trying to understand how the basics in pygame work
I wrote I code where I attempted to make a ball goes up a little bit once the Space key is pressed
So this is my code:
import pygame
import sys
def check_events(ball):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
ball.centery -= 10
class Ball():
def __init__(self,screen):
self.screen=screen
self.rect=self.screen.get_rect()
self.color=(255,255,255)
self.centerx = self.rect.centerx
self.centery = self.rect.centery
self.radius=20
def showcircle(self):
pygame.draw.circle(self.screen, self.color, (self.centerx,self.centery), self.radius)
pygame.init()
screen = pygame.display.set_mode((1000,1000))
screen.fill((20,20,20))
ball=Ball(screen)
while True:
check_events(ball)
ball.showcircle()
pygame.display.update()
The result is this, after pressing the space key several time
My question is why is still showing the previous positions of the ball instead of updating it after pressing the space key again Please, I hope you could help me Thanks in advance
