I am creating a simple mp3 player and my first task was to create a simple button that a user could press. I created a class called Button which handled this behavior and detects if a user has clicked it and then changes color. I am now trying to have a default text that the button displays and another string (pres_string) which will be displayed if the button is being pressed.
The only problem is my background surface seems to be in the wrong place and is drawing over any changes I have made.
Here is my code:
As you can see I've commented out the lines I described and tried it with basic variables in the main function just to test what was going wrong.
Thanks for any help.
(Feel free to change the title of the question, I wasn't sure what most accuratelydescribed my problem)
Clear the surface every loop
tip: For colors, you can call pygame.Color() with human-names like
red
(gray20
andgray80
have a nice contrast, to use for bg and text. )Your button, psuedocode. Fix: moved color as an instance member.
For
testClick
useRect.collidepoint
http://www.pygame.org/docs/ref/rect.html#Rect.collidepoint2D bitmap-based computer graphics are like drawing or painting - you put the new ink on top of whatever was there already. So your background must be the first thing you draw each time.