Troubleshooting¶
This guide addresses common issues you might encounter when using PygameUI and provides solutions.
Component Interaction Issues¶
Components Not Responding to Clicks¶
- Z-Order Issues: Components might be overlapping. Ensure your draw order is correct:
# Draw in the correct order (bottom to top)
background.draw(screen)
button1.draw(screen)
button2.draw(screen) # This will appear on top
- Position Check: Verify that components are positioned within the visible area of the screen.
Input Fields Not Accepting Text¶
Issue: Input components don't register keystrokes.
Solutions:
-
Active State: The input field must be activated by clicking on it first.
-
Events Handling: Make sure you' re passing events to the input component:
- Filter Settings: Check if you've set a filter that might be blocking the characters:
Rendering Issues¶
Components Not Displaying Correctly¶
Issue: Components appear with wrong sizes, colors, or don't display at all.
Solutions:
- Display Setting: Check if the component's display property is enabled:
- Draw Call: Ensure you're calling the draw method for each component:
- Screen Updates: Make sure you're updating the screen after drawing:
- Color Format: Ensure colors are valid RGB tuples with values between 0-255:
# Correct: RGB tuple
my_component.set_color((255, 100, 100))
# Incorrect: values out of range or wrong format
# my_component.set_color((300, 100, 100)) # Values > 255
# my_component.set_color("#FF0000") # Wrong format
Text Rendering Problems¶
Issue: Text appears blurry, wrong size, or doesn't show up.
Solutions:
-
Font Availability: Make sure the specified font family is installed on your system.
-
Anti-aliasing: Try toggling anti-aliasing:
my_text = pygameui.Text(
position=(100, 100),
content="Hello World",
anti_aliasing=True # or False
)
- Size Issues: If text is too small or large, adjust the font size:
Animation Problems¶
Animations Not Working¶
Issue: Flow or jump animations don't run.
Solutions:
- Animation State: Make sure animation is enabled:
- Update Call: Ensure you're calling update in your game loop:
- Position Override: Check that you're not setting the position manually after setting up animations:
- Animation Setup: Verify that animation parameters are correct:
# For flow animation:
my_element.flow(
start_position=(100, 100),
end_position=(300, 100),
time=1000, # milliseconds
loop=True
)
Performance Issues¶
Slow Frame Rate¶
Issue: The application becomes slow when using multiple components.
Solutions:
- Optimize Updates: Only update visible or active components:
# Only update visible components
for component in components:
if component.get_display():
component.update(events)
-
Reduce Animation: Limit the number of animated components.
-
Simplify Rendering: Use simpler shapes or smaller images where possible.
-
Text Caching: For static text, consider creating it once and reusing:
# Create once
my_text = pygameui.Text(position=(100, 100), content="Static Text")
# In the game loop
my_text.draw(screen) # Just draw, no need to update static text
Installation Issues¶
Module Not Found¶
Issue: ImportError: No module named 'pygameui'
Solutions:
-
File Location: Make sure pygameui.py is in the same directory as your project.
-
Running path: Check that you're running your script from the correct directory. If you're using an IDE, ensure the working directory is set to where pygameui.py is located.
-
Initialization: Check that you've imported it correctly:
Additional Help¶
If you're still experiencing issues after trying these solutions:
-
Check Examples: Look at the example code to see working implementations.
-
Review Documentation: Make sure you're using the components as described in the documentation.
-
GitHub Issues: Check existing issues or create a new one with a detailed description of your problem.