0
#Character drawing function
def character(x,y):
    gameDisplay.blit(characterImg,(x,y))

def moveimgsafe(x,y,move):
    if move == True:
        x = 1010
        y = 60
        return x,y
    else:
        return x,y

def highlight_safe(charx,chary,x,y,w,h):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    if x+w > mouse[0] > x and y+h > mouse[1] > y:
            if click[0] == 1:
                 charx,chary = moveimgsafe(charx,chary,movesafe)
                    character(charx,chary)
                    time.sleep(0.5)
                    message_display("You've already opened the safe...")
                    once2 = True
                    return charx,chary



x,y = highlight_safe(x,y,Safe2,Safe1,(Safe3-Safe2),(Safe4-Safe1))

After trying to display the character image with the new co-ordinates after clicking the item, the character is redrawn at the new location but the old image remains until the text goes. I assume this is a clash in the linear code but I'm not sure on a fix. btw - The code isnt in its entirety above but thats the problem area

  • Typically every game loop you will want to draw the background and then draw your images. This will clear old images for objects that have moved. Also you should look at [sprites](https://www.pygame.org/docs/ref/sprite.html), they make handling visible game objects easier. – import random Nov 10 '21 at 12:54

0 Answers0