1

Image of what is occurring

Hi guys, so i'm new to pygame and I'm trying to do something fairly simple. Just move an image across the screen. I've done it before and haven't had this issue. The only change I've made is that I am now blitting 1 image on top of the other.

For some odd reason, this is causing a trail to be left behind.

I've tried Clearing the screen and redrawing and have had no positive results.

Any help would be appreciated.

def main():

    pygame.init()
    screen = pygame.display.set_mode((700,680),0,32)
    clock = pygame.time.Clock()

    bgd_image = pygame.image.load("Grid.png").convert()
    #X Motor Pieces
    MotorXbase = pygame.image.load("MotorXBase.png").convert()
    MotorXbase.set_colorkey((34,177,76))
    MotorXMovePiece = pygame.image.load("MotorXMovePiece.png").convert()
    MotorXMovePiece.set_colorkey((34,177,76))


    #Y Motor Pieces
    MotorYbase = pygame.image.load("MotorYBase.png").convert()
    MotorYbase.set_colorkey((34,177,76))
    MotorYMovePiece = pygame.image.load("MotorYMovePiece.png").convert()
    MotorYMovePiece.set_colorkey((34,177,76))

    screen.fill([34,177,76])
    black = (0,0,0)
    running = True
    xpos = 16
    ypos = 14
    xstep = 1
    ystep = 1
    while running:
        screen.blit(bgd_image,(0,0))
        screen.blit(MotorXbase, [50,550])
        MotorXbase.blit(MotorXMovePiece,[xpos,18])

        screen.blit(MotorYbase, [550,50])
        MotorYbase.blit(MotorYMovePiece,[20,ypos])


        clock.tick(60)
        pygame.display.update()
        screen.fill(black)

        xpos += xstep
        ypos += ystep
        if xpos >399 or xpos <16:
            xstep = -xstep

        if ypos > 397 or ypos < 14:
            ystep = -ystep





    # event handling, gets all event from the eventqueue
        for event in pygame.event.get():
            # only do something if the event is of type QUIT
            if event.type == pygame.QUIT:
                # change the value to False, to exit the main loop
                running = False
user2852630
  • 39
  • 1
  • 8
  • Well, you're blitting the piece images onto the base images, rather than directly onto the screen. This is a destructive operation, you'd have to keep an unmodified copy of the base images, or reload them from disk, to undo the blit. – jasonharper Dec 04 '18 at 16:45
  • @jasonharper Thanks! Worked once I did that change. – user2852630 Dec 04 '18 at 17:30

1 Answers1

0

From comments:

Well, you're blitting the piece images onto the base images, rather than directly onto the screen. This is a destructive operation, you'd have to keep an unmodified copy of the base images, or reload them from disk, to undo the blit.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174