我该如何隐藏和向演员展示python

发布于 2025-01-25 07:13:05 字数 698 浏览 2 评论 0 原文

因此,我正在制作这个游戏,并且我有演员的播放按钮,我该如何制作它,以便当我单击它时,它消失了?在Windows上使用PGZERO。

PS:除了消失的部分,我一切都倒下了。

playbox = Actor("playbox")
createbox = Actor("createbox")
customizebox = Actor("customizebox")
choose_quiz = Actor("choosequiz")

mainboxes = [playbox, createbox, customizebox]

playbox.move_ip(200, 250)
createbox.move_ip(200,360)
customizebox.move_ip(200,470)  
choose_quiz.move_ip(0, 0)

def draw():
    
    playbox.draw()
    createbox.draw()
    customizebox.draw()  

def on_mouse_down(pos):
    #i need 'playbox' to dissapear when I click it
    if playbox.collidepoint(pos):
        print("working")
        screen.clear()
        screen.blit("choosequiz", (0, 0))

So there's this game I'm making and I have the play button as an actor, how do I make it so that when I click it, it disappears? Using pgzero on windows.

PS: I have everything down but the disappearing part.

playbox = Actor("playbox")
createbox = Actor("createbox")
customizebox = Actor("customizebox")
choose_quiz = Actor("choosequiz")

mainboxes = [playbox, createbox, customizebox]

playbox.move_ip(200, 250)
createbox.move_ip(200,360)
customizebox.move_ip(200,470)  
choose_quiz.move_ip(0, 0)

def draw():
    
    playbox.draw()
    createbox.draw()
    customizebox.draw()  

def on_mouse_down(pos):
    #i need 'playbox' to dissapear when I click it
    if playbox.collidepoint(pos):
        print("working")
        screen.clear()
        screen.blit("choosequiz", (0, 0))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苯莒 2025-02-01 07:13:05

您应该使用列表来绘制演员

def draw():
    for item in mainboxes:
        item.draw()

,现在您可以从 Mainboxes 中删除 Playbox 以从屏幕上删除它

def on_mouse_down(pos):
    global mainboxes

    #i need 'playbox' to dissapear when I click it
    if playbox.collidepoint(pos):
        print("working")
        screen.clear()
        screen.blit("choosequiz", (0, 0))
   
        # keep boxes except playbox
        mainboxes = [box for box in mainboxes if box != playbox]

        # or 
        if playbox in mainboxes:
            mainboxes.remove(playbox)

,如果您再次将Actor添加到 Mainboxes 然后它将再次显示。


btw:

使用普通pygame,您可以将对象保留在它具有功能可以简单地从此组中删除对象 - object.kill()

You should use list to draw Actors

def draw():
    for item in mainboxes:
        item.draw()

And now you can remove playbox from mainboxes to remove it from screen

def on_mouse_down(pos):
    global mainboxes

    #i need 'playbox' to dissapear when I click it
    if playbox.collidepoint(pos):
        print("working")
        screen.clear()
        screen.blit("choosequiz", (0, 0))
   
        # keep boxes except playbox
        mainboxes = [box for box in mainboxes if box != playbox]

        # or 
        if playbox in mainboxes:
            mainboxes.remove(playbox)

And if you add actor again to mainboxes then it will be displayed again.


BTW:

With normal PyGame you could keep objects in pygame.sprites.Group and it has function to simply remove object from this group - object.kill()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文