0% found this document useful (0 votes)
5 views2 pages

Pygame Image Animation Example

This document contains a Python script using Pygame to create a simple animation of an image moving horizontally across the screen. The image bounces back when it reaches the window's edges, and the program runs in a loop until the user closes the window. The window is set to a size of 500x500 pixels with a dark gray background.

Uploaded by

Electric claw
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Pygame Image Animation Example

This document contains a Python script using Pygame to create a simple animation of an image moving horizontally across the screen. The image bounces back when it reaches the window's edges, and the program runs in a loop until the user closes the window. The window is set to a size of 500x500 pixels with a dark gray background.

Uploaded by

Electric claw
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import pygame

import sys

[Link]()

# Window setup

screen = [Link].set_mode((500, 500))

[Link].set_caption("Image Animation")

# Load image

image = [Link]("[Link]")

x, y = 50, 200 # Starting position

speed = 5

clock = [Link]()

# Game loop

while True:

for event in [Link]():

if [Link] == [Link]:

[Link]()

[Link]()

# Move image

x += speed

if x > 500 or x < 0:

speed = -speed # Bounce back

[Link]((30, 30, 30)) # Background color

[Link](image, (x, y)) # Draw image

[Link]()
[Link](30) # FPS

You might also like