Blit函数不起作用,循环是否很快?

时间:2019-04-12 14:49:07

标签: python pygame

嘿,我正在为我的Super Mario bross开发重力功能。我希望重力能平稳移动。但是我的播放器就像从顶部到地面传送。

虽然循环太快了,但pygame无法屏蔽图像,但是我尝试使用time.sleep()或pygame.time.wait()来减慢循环速度 它不起作用。 一开始就是这样的: Image : Before Image : One sec later 感谢您的帮助!

def moove(self,keys):     
        if(self.gravity()):
            if keys[pygame.K_LEFT]:
                self.orientation = "Left"
                if not(self.x - vel<0) and not self.collision_with_walls():
                    map.draw()
                    self.rect.x -= vel
                    camera.update(player)
                    self.draw_player()
def gravity(self):
        refresh = 0
        self.collision_with_ground = False
        while not self.collision_with_ground:
            self.rect.y += 1
            blocks_hit_list = pygame.sprite.spritecollide(self,sol_sprites,False)
            if not(blocks_hit_list == []):
                self.collision_with_ground = True
                self.rect.y -= 1
                map.draw()
                player.draw_player()
                return True 
            else:
                map.draw()
                player.draw_player()
                pygame.time.wait(10)

1 个答案:

答案 0 :(得分:0)

在您所在的行:while not self.collision_with_ground:中,您要确保在玩家到达地面之前不会离开此循环。除非离开该循环,否则您永远不会blit(在该循环之外)。尝试使用if而不是一会儿,然后将其他函数移到该循环之外(您可能应该将其移出该函数):

def gravity(self):
        refresh = 0
        self.collision_with_ground = False
        if not self.collision_with_ground:
            self.rect.y += 1
            blocks_hit_list = pygame.sprite.spritecollide(self,sol_sprites,False)
            if not(blocks_hit_list == []):
                self.collision_with_ground = True
                self.rect.y -= 1
                map.draw()
                player.draw_player()
                return True 

        map.draw()
        player.draw_player()
        pygame.time.wait(10)
相关问题