<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                本節實現一個在窗口中自由運動的小球程序,做了詳細注釋,不多做解釋了。 代碼: ~~~ # -*- coding:utf-8 -*- import sys import pygame from pygame.locals import * def play_ball(): pygame.init() #窗口大小 window_size = (width, height) =(700, 500) #小球運行偏移量[水平,垂直],值越大,移動越快 speed = [1, 1] #窗口背景色RGB值 color_black = (0, 0, 139) #設置窗口模式 screen = pygame.display.set_mode(window_size) #設置窗口標題 pygame.display.set_caption('運動的小球') #加載小球圖片 ball_image = pygame.image.load('ball.gif') #獲取小球圖片的區域開狀 ball_rect = ball_image.get_rect() while True: #退出事件處理 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() #使小球移動,速度由speed變量控制 ball_rect = ball_rect.move(speed) #當小球運動出窗口時,重新設置偏移量 if (ball_rect.left < 0) or (ball_rect.right > width): speed[0] =- speed[0] if (ball_rect.top < 0) or (ball_rect.bottom > height): speed[1] =- speed[1] #填充窗口背景 screen.fill(color_black) #在背景Surface上繪制 小球 screen.blit(ball_image, ball_rect) #更新窗口內容 pygame.display.update() if __name__ == '__main__': play_ball() ~~~ 測試: 動畫程序,抓幾張不同時刻的圖片。 1、 ![](https://box.kancloud.cn/2016-06-08_5757935bb4b8c.jpg) 2、 ![](https://box.kancloud.cn/2016-06-08_5757935bc6896.jpg) 3、 ![](https://box.kancloud.cn/2016-06-08_5757935bd9431.jpg) PS: 有朋友說球速度還是太快了,此時可以加個定時器控制一下,如下: ~~~ # -*- coding:utf-8 -*- import sys import pygame from pygame.locals import * def play_ball(): pygame.init() #窗口大小 window_size = (width, height) =(700, 500) #小球運行偏移量[水平,垂直],值越大,移動越快 speed = [1, 1] #窗口背景色RGB值 color_black = (0, 0, 139) #設置窗口模式 screen = pygame.display.set_mode(window_size) #設置窗口標題 pygame.display.set_caption('運動的小球') #加載小球圖片 ball_image = pygame.image.load('ball.gif') #獲取小球圖片的區域開狀 ball_rect = ball_image.get_rect() frames_per_sec = 10 fps_clock = pygame.time.Clock() while True: #退出事件處理 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() #使小球移動,速度由speed變量控制 ball_rect = ball_rect.move(speed) #當小球運動出窗口時,重新設置偏移量 if (ball_rect.left < 0) or (ball_rect.right > width): speed[0] =- speed[0] if (ball_rect.top < 0) or (ball_rect.bottom > height): speed[1] =- speed[1] #填充窗口背景 screen.fill(color_black) #在背景Surface上繪制 小球 screen.blit(ball_image, ball_rect) #更新窗口內容 pygame.display.update() fps_clock.tick(frames_per_sec) if __name__ == '__main__': play_ball() ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看