I am trying to make a pygame zero game. The step I am up to is choosing the character I have some images and i want to create interactive character selection buttons using images. I am currently using screen.blit
Here is my code:
def draw_button(rect, text, color='yellow'):
screen.draw.filled_rect(rect, color)
screen.draw.textbox(text, rect, fontname='impact', color='black')
screen.blit('thor', spaces_char[0])
screen.blit('loki', spaces_char[1])
I have been looking for a way on the internet but they are very unhelpful because i am using pygame zero, not pygame!!!!! I tried with the code above. Does Surface work? Really what I am trying to do is make a Rect to be detected with on_mouse_down() The files are thor.png and loki.png Thanks
I am trying to make a pygame zero game. The step I am up to is choosing the character I have some images and i want to create interactive character selection buttons using images. I am currently using screen.blit
Here is my code:
def draw_button(rect, text, color='yellow'):
screen.draw.filled_rect(rect, color)
screen.draw.textbox(text, rect, fontname='impact', color='black')
screen.blit('thor', spaces_char[0])
screen.blit('loki', spaces_char[1])
I have been looking for a way on the internet but they are very unhelpful because i am using pygame zero, not pygame!!!!! I tried with the code above. Does Surface work? Really what I am trying to do is make a Rect to be detected with on_mouse_down() The files are thor.png and loki.png Thanks
Share Improve this question edited Mar 22 at 6:12 Rabbid76 211k30 gold badges158 silver badges200 bronze badges asked Mar 22 at 4:05 user29854913user29854913 12 bronze badges 01 Answer
Reset to default 0You need to define Rect
for a clickable area. screen.draw.textbox
is for text only. So your code might look something like this:
thor_rect = Rect(100, 100, 64, 64)
screen.blit('thor', thor_rect.topleft)
def on_mouse_down(pos):
if thor_rect.collidepoint(pos):
print("Thor selected!")
I added on_mouse_down()
to handle mouse events.