'Pygame button in gamescreen
I have placed a button in a pong game where the game is playing, I am able to start the game but the only thing that appears is the button and not the game, therefore the problem I have is that no game appears. I do not know what part of the code you would like me to attach. I will link to the code instead, https://replit.com/@ii2/HospitableLustrousPipeline#main.py
Solution 1:[1]
The problem is in your main loop. What happens is:
- Screen is filled black
- New button instance is created (note that this is a bug, because you do not need more than 1 instance of this button, it has to be created just once like sprites)
- Display is updated and pygame clock's tick is called, so up to this point you can see black screen with just a button
But then other half of the loop is executed which again fills screen black and displays sprites and board. So what you see is a combination of these two colliding parts. The reason why you see just the first part of the loop is because clock.tick() which controls refresh rate in this case. If there would be second tick() call as the last line in the loop most likely you could see the board and also the button.
To fix that you have to delete first (line 112) pygame.display.update() and second (line 151) screen.fill(BLACK) call. That should work. Besides that I would suggest calling clock.tick() once just after display.flip() at the end of the loop.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kcper |
