I am trying to remove an image from memory to increase the efficiency of my code without the use of SpriteGroups as I am unfamiliar with that concept.
import pygame
import sys
pygame.init()
#constants
LENGTH = 454
SCREEN = pygame.display.set_mode((LENGTH, LENGTH))
def show(img, x, y):
image = pygame.image.load(img)
SCREEN.blit(image, (x, y))
def home():
show('image1.png', 10, 10)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
#code to remove the image
pass
def main():
while True:
SCREEN.fill((0, 0, 0))
home()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
main()
Here is a simple minimal code to keep the problem as general as possible all this code does is to remove the image on pressing space. Earlier I tried approaching it by either taking it outside the screen, or just rendering other objects over it. However the image isn't deleted completely I want to remove it not only from play but also from memory.
From past few days the 'www.pygame.org' site has been in solidarity hence unable to refer to the documentation