Pygame sprite won't move with "event.type KEYDOWN"
The Ball() class will not get the information from the KEYDOWN/KEYUP in "for event in pygame.event.get()" so the ball will not move across the screen. It displays at the right coordinates but fails to move, which confuses me. Here is the code:

    import pygame, sys
    from pygame.locals import *
    pygame.init()
    
    red = (255,0,0)
    green = (0,255,0)
    blue = (0,0,255)
    darkBlue = (0,0,128)
    white = (255,255,255)
    black = (0,0,0)
    pink = (255,200,200)
    
    background = pygame.image.load('background.jpg')
    screen = pygame.display.set_mode((640,521),0,32)
    
    pygame.display.set_caption('V1.1')
    s = 0 #s and s2 for displaying score later on
    s2 = 0
    
    class Ball():
        def __init__(self):
            ball = pygame.sprite.Sprite()
            ball.image = pygame.image.load('red_ball.png').convert()
            ball.rect = ball.image.get_rect()
            ball.image.set_colorkey((white))
            screen.blit(ball.image,(x,y))
            pygame.display.update()
        def update(self):
            if x > 640:
                x = 0
            if x < 0:
                x = 640
    
    def main():
        while 1:
            screen.blit(background, (0,0))
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
            Ball()
            pygame.display.update()
    
    
    x,y = 285, 430
    m_x, m_y = 0,0
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_a:
                m_x = -4
                s+=1
            elif event.key == K_d:
                m_x = +4
                s2+=1
        elif event.type == KEYUP:
            if event.key == K_a:
                m_x = 0
            elif event.key == K_d:
                m_x = 0
    x+= m_x
    y+= m_y
    
    
    main()









Pygame sprite won't move with "event.type KEYDOWN"
===

The Ball() class will not get the information from the KEYDOWN/KEYUP in "for event in pygame.event.get()" so the ball will not move across the screen. It displays at the right coordinates but fails to move, which confuses me. Here is the code:

    import pygame, sys
    from pygame.locals import *
    pygame.init()
    
    red = (255,0,0)
    green = (0,255,0)
    blue = (0,0,255)
    darkBlue = (0,0,128)
    white = (255,255,255)
    black = (0,0,0)
    pink = (255,200,200)
    
    background = pygame.image.load('background.jpg')
    screen = pygame.display.set_mode((640,521),0,32)
    
    pygame.display.set_caption('V1.1')
    s = 0 #s and s2 for displaying score later on
    s2 = 0
    
    class Ball():
        def __init__(self):
            ball = pygame.sprite.Sprite()
            ball.image = pygame.image.load('red_ball.png').convert()
            ball.rect = ball.image.get_rect()
            ball.image.set_colorkey((white))
            screen.blit(ball.image,(x,y))
            pygame.display.update()
        def update(self):
            if x > 640:
                x = 0
            if x < 0:
                x = 640
    
    def main():
        while 1:
            screen.blit(background, (0,0))
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
            Ball()
            pygame.display.update()
    
    
    x,y = 285, 430
    m_x, m_y = 0,0
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_a:
                m_x = -4
                s+=1
            elif event.key == K_d:
                m_x = +4
                s2+=1
        elif event.type == KEYUP:
            if event.key == K_a:
                m_x = 0
            elif event.key == K_d:
                m_x = 0
    x+= m_x
    y+= m_y
    
    
    main()








