A virtual thumb pad for directional input, featuring a central donut shape and a movable button pad.
Project description
PyThumbPad
PyThumbPad is a customizable virtual thumb pad for directional input, designed for use in Pygame projects. It features a central donut-shaped control area and a movable button pad, making it ideal for mobile games or any application requiring a thumb stick-style input.
Features
- Customizable Appearance: Easily change colors and sizes for the donut and button pad.
- Directional Input: Supports 4 or 8 directional quadrants for precise input.
- Simple Integration: Easy to add to any Pygame project with minimal setup.
- Responsive Input Handling: Smoothly tracks user input and updates the direction accordingly.
Installation using PyPI
You can install the py_thumbpad
package directly from PyPI using pip:
pip install py_thumbpad
Installation using GIT
Clone the repository and include the py_thumbpad
package in your Pygame project.
git clone https://github.com/kerodekroma/py-thumbpad.git
Usage
Here's a basic example of how to use PyThumbPad in your Pygame project:
import pygame
from py_thumbpad import PyThumbPad
# Initialize Pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
# Create a PyThumbPad instance
thumb_pad = PyThumbPad((400, 300), {"quadrants": 8})
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Listen for events on the thumb pad
thumb_pad.listen_events(event)
# Update thumb pad state
thumb_pad.update()
# Render everything
screen.fill((0, 0, 0))
thumb_pad.render(screen)
pygame.display.flip()
pygame.quit()
Options
When initializing PyThumbPad, you can pass a dictionary of options to customize the appearance and behavior:
-
quadrants
: The number of directional quadrants (4 for up, down, left, right; 8 for diagonals as well). Default is 4. -
donut_color
: The color of the donut-shaped pad. Default is (123, 157, 243). -
button_color
: The color of the movable button pad. Default is (255, 255, 0). -
donut_bg_color
: The background color of the donut. Default is (0, 0, 0).
Example:
thumb_pad = PyThumbPad((400, 300), {
"quadrants": 8,
"donut_color": (200, 100, 100),
"button_color": (100, 200, 100),
"donut_bg_color": (50, 50, 50)
})
Methods
update()
Updates the state of the button pad. This method should be called within the game loop.
render(screen)
Renders the thumb pad on the provided Pygame surface.
listen_events(event)
Handles Pygame input events and updates the thumb pad's state.
get_directions(current_angle)
Returns the direction based on the current angle and the number of quadrants. This method is used internally by listen_events.
Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue to discuss any changes or improvements.
License
This project is licensed under the MIT License - see the MIT-LICENSE.txt file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py_thumbpad-1.0.1.tar.gz
.
File metadata
- Download URL: py_thumbpad-1.0.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4337a0d8f202ff4f035f73f999fa9bad2e59bbc59ec2fe39d29461e4f05011ce |
|
MD5 | eacb3faaed05419cce710b890c02c3ea |
|
BLAKE2b-256 | cda99e952ae5a098a1235e427b9d3dc8f0a82701fda1a5bc796f231de4e7405e |
File details
Details for the file py_thumbpad-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: py_thumbpad-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bb15824c17e8b5c9f55eb7612a149ba295e6ccc928718e7e8eafecc6f0eb827 |
|
MD5 | 3d0f42ab3478460ba9ce7191930e2a91 |
|
BLAKE2b-256 | d16606ddf2465f341f1294b00184cd2a61f40cf7b4677e3942d16de1790aacbc |