Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
pygame-click-manager
Advanced tools
pygame_click_manager
is a Python module designed to facilitate the handling of mouse events and collisions within the Pygame framework. The main class, ClickManager
, provides methods to check for button clicks, verify if the mouse is within a specified area, and determine if one object is inside or colliding with another object.
To use pygame_click_manager
, ensure you have Pygame installed:
pip install pygame
Then, include pygame_click_manager
in your project by copying the class definition into your codebase.
Here's a basic example of how to use the ClickManager
class:
import pygame
from pygame_click_manager import ClickManager
# Initialize Pygame
pygame.init()
# Create a screen
screen = pygame.display.set_mode((800, 600))
# Define a command to be executed on button click
def button_command():
print("Button clicked!")
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Check for button clicks
if ClickManager.check_buttons_for_clicks((100, 100), (150, 50), button_command):
print("Button area was clicked.")
# Your game logic here
# Update the display
pygame.display.update()
pygame.quit()
ClickManager
check_buttons_for_clicks(starting_pos: tuple[int, int], size: tuple[int, int], command=None) -> bool
starting_pos
: The top-left corner of the button area.size
: The width and height of the button area.command
: An optional command (function) to be executed when the button is clicked.True
if the button is clicked, otherwise False
._is_mouse_in_area(starting_pos: tuple[int, int], size: tuple[int, int]) -> bool
starting_pos
: The top-left corner of the area.size
: The width and height of the area.True
if the mouse is in the area, otherwise False
.is_object_inside_another(start_pos_1: tuple[int, int], size_1: tuple[int, int], start_pos_2: tuple[int, int], size_2: tuple[int, int]) -> bool
start_pos_1
: The top-left corner of the first object.size_1
: The width and height of the first object.start_pos_2
: The top-left corner of the second object.size_2
: The width and height of the second object.True
if the second object is inside the first object, otherwise False
.is_object_colliding_with_another(start_pos_1: tuple[int, int], size_1: tuple[int, int], start_pos_2: tuple[int, int], size_2: tuple[int, int]) -> bool
start_pos_1
: The top-left corner of the first object.size_1
: The width and height of the first object.start_pos_2
: The top-left corner of the second object.size_2
: The width and height of the second object.True
if the objects are colliding, otherwise False
.This project is licensed under the MIT License.
FAQs
A package for managing clicks in pygame.
We found that pygame-click-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.