I am trying to make an Undertale like game in python - However I have a problem. When I try to 'blit' an image to the screen it doesn't show. I am 'blitting' a heart and I have rescaled it to an appropriate size in a 3rd party program.
import pygame # Imports Pygame Library
import keyboard # Imports Keyboard Library
# Defining Image Components
undertale_logo_ico = pygame.image.load('Undertale_Logo.ico')
Soul_Heart_Red = pygame.image.load('UndertaleHeart.png')
# Define Key-presses
def movement(key_pressed):
if key_pressed == 'right':
print('Right')
elif key_pressed == 'left':
print('Left')
elif key_pressed == 'up':
print('Up')
elif key_pressed == 'down':
print('Down')
else:
print('Not registered key')
# Execute Key Presses:
keyboard.on_press_key("right arrow", lambda _: movement('right'))
keyboard.on_press_key("left arrow", lambda _: movement('left'))
keyboard.on_press_key("up arrow", lambda _: movement('up'))
keyboard.on_press_key("down arrow", lambda _: movement('down'))
keyboard.on_press_key("d", lambda _: movement('right'))
keyboard.on_press_key("a", lambda _: movement('left'))
keyboard.on_press_key("w", lambda _: movement('up'))
keyboard.on_press_key("s", lambda _: movement('down'))
# Display Window Configuration
# area = screen.get_rect()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
background_colour = (0, 0, 0)
(width, height) = (300, 200)
pygame.display.set_caption('Game 1')
screen.fill(background_colour)
pygame.display.set_icon(undertale_logo_ico)
pygame.display.flip()
# Drawing Player
screen.blit(Soul_Heart_Red, [0, 0])
# Closing Script
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
The blit() is near the bottom of the code.
You have to update the display after blit
:
screen.blit(Soul_Heart_Red, [0, 0])
pygame.display.flip() # <---