简体   繁体   English

开始屏幕不显示

[英]Start screen isn't showing up

After I got the paddles to move properly, the start screen stopped showing up at the beginning.在我让桨正确移动后,开始屏幕在开始时停止显示。 I want it to show the actual game screen when you press enter, which worked, until I added the paddles.我希望它在您按下回车键时显示实际的游戏屏幕,这很有效,直到我添加了桨。 I know for a fact that the problem has to do with the display update, but I'm not sure how to fix it.我知道问题与显示更新有关,但我不确定如何解决。

Here's the game loop:这是游戏循环:

while not x:
  for event in pygame.event.get():
    if event.type == pygame.QUIT: 
      x = True #quits the game when you press X
    if event.type == pygame.KEYUP: #makes start screen go away
      if event.key == pygame.K_RETURN:
        gameScreen() #has the black background and lines

  #moves the paddles
    if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_w: #makes blue paddle go up
        p1Paddle.state = 'up'
        p1Paddle.move()
        
    if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_s: #makes blue paddle go down
        p1Paddle.state = 'down'
        p1Paddle.move()

    if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_UP: #makes red paddle go up
        p2Paddle.state = 'up'
        p2Paddle.move()
        
    if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_DOWN: #makes red paddle go down
        p2Paddle.state = 'down'
        p2Paddle.move()

        
    gameScreen() #updates the display (problem- not sure what to put instead)
        
    p1Paddle.show()
    p2Paddle.show()
    ball.show()

You can use pygame.display.update() instead of the gameScreen function to update the display.您可以使用pygame.display.update()代替 gameScreen 函数来更新显示。 However, this doesn't seem to impact the game screen not showing.但是,这似乎不会影响游戏画面不显示。 To fix the game screen not showing, try using the function pygame.display.set_mode((width,height)) to set the screen's size and display it.要修复游戏屏幕不显示的问题,请尝试使用函数pygame.display.set_mode((width,height))设置屏幕大小并显示它。

Some example code with the use of these functions is below.下面是一些使用这些函数的示例代码。 Try adding it at the very beginning of the entire code and see if it shows the game screen after pressing enter.尝试在整个代码的最开始添加它,看看它是否在按下回车后显示游戏屏幕。

width = 500 #screen width
height = 200 #screen height
if event.key == pygame.K_RETURN: # show screen when enter key is pressed
    pygame.display.set_mode((width, height)) #creates screen
    gameScreen() # has the black background and lines

I fixed it!我修好了它! (sort of*) (有点*)

I added a variable, start , before the loop and set it as false.我在循环之前添加了一个变量start并将其设置为 false。 Then, at the end of the loop I replaced this:然后,在循环结束时,我替换了这个:

    gameScreen() #updates the display (problem- not sure what to put instead)
        
    p1Paddle.show()
    p2Paddle.show()
    ball.show()

with this:有了这个:

    if start == True:
      gameScreen()
      p1Paddle.show() #make the paddles and ball show up vv
      p2Paddle.show()
      ball.show()

*Now the start screen shows up, but the paddles show up over it at the start- but that's it's own problem. *现在开始屏幕出现了,但桨在开始时出现在它上面 - 但这是它自己的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM