Confused at why PyGame display's a black screen

前端 未结 2 933
花落未央
花落未央 2021-01-15 21:08

So before I decided to ask this question I did a little research to see what my problem was and came across this: Code Only Produces Black Screen In Pygame Window However th

相关标签:
2条回答
  • 2021-01-15 21:15

    Ok so I have now solved my problem. (aha novice error). So in the __init__(self) area within class Pane() I added the line self.Screen.fill((white)) to make it look like this:

        def __init__(self):
            self.Screen = pygame.display.set_mode((1000,600), 0, 32)
            self.font = pygame.font.SysFont('Arial', 25)
            self.Screen.fill((white))
    

    I'm not sure if this is the best way to solve the problem but it works. So that's good. However if you think that this isn't a good way to solve the problem then by all means teach me of a better way to solve my problem.

    0 讨论(0)
  • 2021-01-15 21:40

    Problem is your code organization.

    You have tree times pygame.display.set_mode(). Every time you call pygame.display.set_mode() you destroy previous screen, create new screen and new screen is always black.

    You should create screen only once and send it to other class as parameter.

    def addPane(self, textToDisplay):
        myPane = Pane(self.screen) # send screen to Pane
        myPane.drawPane(textToDisplay)
    
    # ...
    
    class Pane():
    
        def __init__(self, screen):
            self.Screen = screen # get screen 
    

    And remove pygame.display.set_mode() from clear() function - use one screen to the end of the program.

    Now I can see your pane with "hello"

    0 讨论(0)
提交回复
热议问题