最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Can a screen.draw.textbox function be passed an image - Stack Overflow

programmeradmin3浏览0评论

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 0
Add a comment  | 

1 Answer 1

Reset to default 0

You 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.

发布评论

评论列表(0)

  1. 暂无评论