Caleb Shaw
Caleb Shaw

Reputation: 73

How would I blit something before another thing in pygame?

I was wondering how I could blit an image before another image depending on their y position. I want to make a game like pokemon, where if you are behind somethin, it appears over you (it has blitted after you), but if you are in front of it, it blits before you. Thanks.

Upvotes: 0

Views: 602

Answers (1)

Stellan
Stellan

Reputation: 206

Usually in pygame, the image that is blitted last has priority over others, resulting in that image being displayed on top of all others. Here is an example:

import pygame

Img1 = pygame.image.load('Number1.png')
Img2 = pygame.image.load('Number2.png')

pygame.init()
#Initiate screen
screen = pygame.display.set_mode((700, 700))
done = False

while not done:
        for event in pygame.event.get():
                if event.type == pygame.QUIT:                    
                        done = True
        #Blit the images
        screen.blit(Img1,(200,200))
        screen.blit((Img2),(300,300))

        pygame.display.flip()

Since we blitted the number2 after the number 1, the number2 will be blitted ontop of the number 1 as shown below. Click this link for result

Upvotes: 2

Related Questions