TIMED WORDS ON WINDOW:
pygame.init()
window = pygame.display.set_mode((500, 500))
font = pygame.font.Font(None, 36)
text_surface = font.render('WORDS HERE', True, (255, 255, 255))
text_rect = text_surface.get_rect()
text_rect.center = (250, 250)
running = True
duration = 3000 # Duration in milliseconds (3 seconds)
start_time = pygame.time.get_ticks()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
current_time = pygame.time.get_ticks()
elapsed_time = current_time - start_time
if elapsed_time >= duration:
running = False
window.fill((0, 0, 0))
window.blit(text_surface, text_rect)
pygame.display.update()
ADDING A TIMED IMAGE ON WINDOW
# Initialize Pygame
pygame.init()
WIDTH, HEIGHT = 800, 600
FPS = 60
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
# Load image
image = pygame.image.load('image.png') # Replace 'image.png' with your image file
path
image_rect = image.get_rect()
# Set the duration of the image in seconds
duration = 3
show_image = True
start_time = pygame.time.get_ticks()
# Game loop
running = True
while running:
clock.tick(FPS)
# Event handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Calculate elapsed time since the start
elapsed_time = (pygame.time.get_ticks() - start_time) / 1000 # Convert
milliseconds to seconds
# Drawing
screen.fill((255, 255, 255)) # Fill the screen with white color
# Display the image if elapsed time is less than the duration
if show_image and elapsed_time < duration:
screen.blit(image, (WIDTH//2 - image_rect.width//2, HEIGHT//2 -
image_rect.height//2))
else:
show_image = False
pygame.display.flip()
# Quit the game
pygame.quit()