问题
I made my enemy class and underneath it I made a funtion that lets my enemy move left and right but for some reason it blits more then 1 enemy and stay at one position VIDEO
# enemys class
class enemy:
def __init__(self,x,y,height,width,color):
self.x = x
self.y =y
self.esright = [pygame.image.load("esright1.png"),
pygame.image.load("esright1.png"),
pygame.image.load("esright2.png"),
pygame.image.load("esright3.png"),
pygame.image.load("esright4.png"),
pygame.image.load("esright5.png"),
pygame.image.load("esright6.png"),
pygame.image.load("esright7.png"),
pygame.image.load("esright8.png"),
pygame.image.load("esright9.png"),
pygame.image.load("esright10.png"),
pygame.image.load("esright11.png"),
pygame.image.load("esright12.png"),
pygame.image.load("esright13.png"),
pygame.image.load("esright14.png"),
pygame.image.load("esright15.png"),
pygame.image.load("esright16.png"),
pygame.image.load("esright17.png"),
]
self.esleft = [pygame.image.load("esleft1.png"),
pygame.image.load("esleft1.png"),
pygame.image.load("esleft2.png"),
pygame.image.load("esleft3.png"),
pygame.image.load("esleft4.png"),
pygame.image.load("esleft5.png"),
pygame.image.load("esleft6.png"),
pygame.image.load("esleft7.png"),
pygame.image.load("esleft8.png"),
pygame.image.load("esleft9.png"),
pygame.image.load("esleft10.png"),
pygame.image.load("esleft11.png"),
pygame.image.load("esleft12.png"),
pygame.image.load("esleft13.png"),
pygame.image.load("esleft14.png"),
pygame.image.load("esleft15.png"),
pygame.image.load("esleft16.png"),
pygame.image.load("esleft17.png"),
]
self.esright = [pygame.transform.scale(image,(image.get_width()//3,image.get_height()//3)) for image in self.esright]
self.esleft = [pygame.transform.scale(image,(image.get_width()//3,image.get_height()//3)) for image in self.esleft]
self.height = height
self.width = width
self.vel = 5
self.color = color
self.anim_index = 0
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
window.blit(self.esright[self.anim_index], self.rect)
self.anim_index += 1
if self.anim_index == len(self.esright):
self.anim_index = 0
if self.x < 250:
self.image_list.x -= self.vel
else:
window.blit(self.esleft[self.anim_index], self.rect)
if self.anim_index == len(self.esleft):
self.anim_index = 0
if self.y > 350:
self.image_list.y += self.vel
来源:https://stackoverflow.com/questions/62012073/enemys-wont-move-left-and-right-how-do-i-fix-this