Python I';我在pygame动画方面有问题

Python I';我在pygame动画方面有问题,python,animation,pygame,Python,Animation,Pygame,我对编码还很陌生,我在pygame中的动画方面遇到了一些问题,我看到的不是移动的而是静止的图像 import pygame import os pygame.init() Stationary = pygame.image.load(os.path.join("Assets", "stationary.png")) left = [pygame.image.load(os.path.join("Assets", "L1.p

我对编码还很陌生,我在pygame中的动画方面遇到了一些问题,我看到的不是移动的而是静止的图像

import pygame
import os

pygame.init()

Stationary = pygame.image.load(os.path.join("Assets", "stationary.png"))
left = [pygame.image.load(os.path.join("Assets", "L1.png")),
        pygame.image.load(os.path.join("Assets", "L2.png")),
        pygame.image.load(os.path.join("Assets", "L3.png")),
        pygame.image.load(os.path.join("Assets", "L4.png"))
        ]
right = [pygame.image.load(os.path.join("Assets", "R1.png")),
         pygame.image.load(os.path.join("Assets", "R2.png")),
         pygame.image.load(os.path.join("Assets", "R3.png")),
         pygame.image.load(os.path.join("Assets", "R4.png"))
         ]

WIDTH, HEIGHT = 500, 300
screen = pygame.display.set_mode((WIDTH, HEIGHT))
BLACK = 0, 0, 0
vel = 0.5
stepIndex = 0
clock = pygame.time.Clock()
FPS = 60
move_left = False
move_right = False
x = 50
y = 250


def draw_screen():
    global stepIndex
    screen.fill(BLACK)
    if stepIndex >= 8:
        stepIndex = 0
    if move_left:
        screen.blit(left[stepIndex//2], (x, y))
    elif move_right:
        screen.blit(right[stepIndex//2], (x, y))
    else:
        screen.blit(Stationary, (x, y))


running = True
while running:
    clock.tick(FPS)
    draw_screen()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    keys_pressed = pygame.key.get_pressed()
    if keys_pressed[pygame.K_d]:
        x += vel
        move_right = True
        move_left = False
    elif keys_pressed[pygame.K_a]:
        x -= vel
        move_right = False
        move_left = True
    else:
        move_left = False
        move_right = False
        stepIndex = 0

    pygame.display.update()

pygame.quit()


我已经盯着我的代码看了大约2个小时,在互联网上搜索解决方案,得到了这个结果,我甚至看了谷歌搜索的第二页,只是为了找到我的问题的一些答案。

你错过了增量
步骤索引

def draw_screen():
全局阶跃指数
屏幕填充(黑色)
步骤索引+=1#=8:
步骤索引=0
如果向左移动,请执行以下操作:
blit(左[步进索引//2],(x,y))
elif向右移动:
blit(右[stepIndex//2],(x,y))
其他:
屏幕布利特(静止,(x,y))