0% found this document useful (0 votes)
4 views

Pygame Built in Functions

Uploaded by

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

Pygame Built in Functions

Uploaded by

s.amudhan2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Pygame Built-in Functions

1. Initialization and Quitting Functions:


- pygame.init(): Initializes all imported Pygame modules.
- pygame.quit(): Uninitializes all Pygame modules, closing windows and freeing up
resources.

2. Display Functions:
- pygame.display.set_mode(size): Initializes a window or screen for display.
- pygame.display.flip(): Updates the entire screen.
- pygame.display.update(): Updates portions of the screen.
- pygame.display.set_caption(title): Sets the window's title.
- pygame.display.get_surface(): Gets the current display surface object.

3. Event Functions:
- pygame.event.get(): Returns a list of all events currently in the event queue.
- pygame.event.poll(): Retrieves a single event from the queue.
- pygame.event.wait(): Waits for an event to appear in the queue.
- pygame.event.clear(): Clears the event queue.
- pygame.event.post(event): Adds an event to the queue.

4. Drawing Functions:
- pygame.draw.rect(surface, color, rect): Draws a rectangle.
- pygame.draw.circle(surface, color, center, radius): Draws a circle.
- pygame.draw.line(surface, color, start_pos, end_pos): Draws a line.
- pygame.draw.polygon(surface, color, points): Draws a polygon.

5. Surface Functions:
- pygame.Surface(size): Creates a new Surface.
- surface.fill(color): Fills the entire surface with a solid color.
- surface.blit(source, dest): Draws one Surface onto another.
- surface.get_at(pos): Gets the color of the pixel at the pos.
- surface.set_at(pos, color): Sets the color of the pixel at pos.

6. Time Functions:
- pygame.time.Clock(): Creates an object to help control the frame rate.
- clock.tick(framerate): Limits the program to run at a maximum of framerate.
- pygame.time.get_ticks(): Returns the number of milliseconds since Pygame was
initialized.
- pygame.time.delay(milliseconds): Pauses the program for a given number of
milliseconds.

7. Font Functions:
- pygame.font.Font(file, size): Loads a font from the specified file.
- font.render(text, antialias, color): Renders the given text as a Surface.

8. Image Functions:
- pygame.image.load(filename): Loads an image from a file.
- pygame.image.save(surface, filename): Saves a Surface to an image file.

9. Sound and Music Functions:


- pygame.mixer.Sound(file): Loads a sound file and returns a Sound object.
- sound.play(): Plays the Sound object.
- pygame.mixer.music.load(file): Loads a music file for playback.
- pygame.mixer.music.play(loops): Plays the loaded music file.
- pygame.mixer.music.stop(): Stops the currently playing music.

10. Joystick Functions:


- pygame.joystick.init(): Initializes the joystick module.
- pygame.joystick.Joystick(id): Creates a joystick object with the specified id.
- joystick.get_numaxes(): Gets the number of axes on the joystick.
- joystick.get_button(button): Gets the state of a particular button on the
joystick.

11. Key and Mouse Functions:


- pygame.key.get_pressed(): Returns the state of all keyboard keys.
- pygame.mouse.get_pos(): Gets the current position of the mouse.
- pygame.mouse.get_pressed(): Gets the current state of the mouse buttons.

12. Rect Functions:


- pygame.Rect(left, top, width, height): Creates a new Rect object.
- rect.collidepoint(x, y): Checks if a point is inside the rect.
- rect.colliderect(rect): Checks if this rect collides with another.

You might also like