• <tfoot id='iUj2v'></tfoot>

    <legend id='iUj2v'><style id='iUj2v'><dir id='iUj2v'><q id='iUj2v'></q></dir></style></legend>

        <bdo id='iUj2v'></bdo><ul id='iUj2v'></ul>

    1. <i id='iUj2v'><tr id='iUj2v'><dt id='iUj2v'><q id='iUj2v'><span id='iUj2v'><b id='iUj2v'><form id='iUj2v'><ins id='iUj2v'></ins><ul id='iUj2v'></ul><sub id='iUj2v'></sub></form><legend id='iUj2v'></legend><bdo id='iUj2v'><pre id='iUj2v'><center id='iUj2v'></center></pre></bdo></b><th id='iUj2v'></th></span></q></dt></tr></i><div id='iUj2v'><tfoot id='iUj2v'></tfoot><dl id='iUj2v'><fieldset id='iUj2v'></fieldset></dl></div>
    2. <small id='iUj2v'></small><noframes id='iUj2v'>

        按住键时如何进行精灵移动

        时间:2024-04-22

        <small id='bPnRB'></small><noframes id='bPnRB'>

          <tbody id='bPnRB'></tbody>

          <tfoot id='bPnRB'></tfoot>
            <i id='bPnRB'><tr id='bPnRB'><dt id='bPnRB'><q id='bPnRB'><span id='bPnRB'><b id='bPnRB'><form id='bPnRB'><ins id='bPnRB'></ins><ul id='bPnRB'></ul><sub id='bPnRB'></sub></form><legend id='bPnRB'></legend><bdo id='bPnRB'><pre id='bPnRB'><center id='bPnRB'></center></pre></bdo></b><th id='bPnRB'></th></span></q></dt></tr></i><div id='bPnRB'><tfoot id='bPnRB'></tfoot><dl id='bPnRB'><fieldset id='bPnRB'></fieldset></dl></div>
              <bdo id='bPnRB'></bdo><ul id='bPnRB'></ul>

                1. <legend id='bPnRB'><style id='bPnRB'><dir id='bPnRB'><q id='bPnRB'></q></dir></style></legend>
                2. 本文介绍了按住键时如何进行精灵移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  目前,每次按下一个键,精灵只会移动 1 个像素.按住左键或右键时,如何使水管工精灵不断移动?

                  Currently the sprite only moves 1 pixel every time a key is pressed. How could I cause the plumber sprite to move constantly when left or right key is being held down?

                  while running:
                      setup_background()
                      spriteimg = plumberright
                  
                      screen.blit(spriteimg,(x1, y1))
                  
                      for event in pygame.event.get():
                           if event.type == pygame.QUIT:
                               running = False
                           elif event.type == pygame.KEYDOWN:
                               if event.key == pygame.K_UP:
                                   x1 = x1 + 0
                                   y1 = y1 - 1
                               elif event.key == pygame.K_DOWN:
                                   x1 = x1 + 0
                                   y1 = y1 + 1
                               elif event.key == pygame.K_LEFT:
                                   x1 = x1 -1
                                   y1 = y1 + 0
                               elif event.key == pygame.K_RIGHT:
                                   x1 = x1 + 1
                                   y1 = y1 + 0
                  
                      pygame.display.flip()
                      clock.tick(120)
                  

                  推荐答案

                  你可以使用 pygame.key.get_pressed 这样做.

                  You can use pygame.key.get_pressed to do that.

                  示例:

                  while running:
                      keys = pygame.key.get_pressed()  #checking pressed keys
                      if keys[pygame.K_UP]:
                          y1 -= 1
                      if keys[pygame.K_DOWN]:
                          y1 += 1
                  

                  这篇关于按住键时如何进行精灵移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何刷新打印函数的输出(取消缓冲 python 输出)? 下一篇:为什么“pip install"?在 Python 内部引发 SyntaxError?

                  相关文章

                    <i id='1rhde'><tr id='1rhde'><dt id='1rhde'><q id='1rhde'><span id='1rhde'><b id='1rhde'><form id='1rhde'><ins id='1rhde'></ins><ul id='1rhde'></ul><sub id='1rhde'></sub></form><legend id='1rhde'></legend><bdo id='1rhde'><pre id='1rhde'><center id='1rhde'></center></pre></bdo></b><th id='1rhde'></th></span></q></dt></tr></i><div id='1rhde'><tfoot id='1rhde'></tfoot><dl id='1rhde'><fieldset id='1rhde'></fieldset></dl></div>

                    • <bdo id='1rhde'></bdo><ul id='1rhde'></ul>
                    <tfoot id='1rhde'></tfoot><legend id='1rhde'><style id='1rhde'><dir id='1rhde'><q id='1rhde'></q></dir></style></legend>

                      <small id='1rhde'></small><noframes id='1rhde'>