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))
janajayjana
  • 3
  • 1
  • 4
  • 1
    [Actors](https://pygame-zero.readthedocs.io/en/stable/builtins.html#actors) are objects of [Pygame Zero](https://pygame-zero.readthedocs.io/en/stable/), but not of [Pygame](https://www.pygame.org/news) – Rabbid76 Apr 29 '22 at 20:58
  • 1
    Hi there, could you please add a little detail more to your question. Perhaps you could add the relevant code? – jda5 Apr 29 '22 at 21:06
  • keep actors on list and in `draw()` use `for item in mainboxes: item.draw()` instead of `playbox.draw()`, etc. And then you can remove it from list and it will remove from screen. – furas Apr 29 '22 at 21:43

1 Answers1

0

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()

furas
  • 134,197
  • 12
  • 106
  • 148