StanislavPetrovV / DOOM-style-Game

DOOM-style 3D (raycasting) Game in Python Pygame
MIT License
550 stars 242 forks source link

AnimatedSprite.get_images method returns sprite images in incorrect order #2

Open barrymun opened 1 year ago

barrymun commented 1 year ago

Development on mac may result in the return of sprite images in the incorrect order. For example, your weapon may start off in the firing state and look strange when using it, or the animation of npc's may look odd. I propose using the natsort library to sort the animated sprite pngs. So add this to the requirements.txt: natsort==8.2.0 and change def get_images(self, path): images = deque() for file_name in os.listdir(path): if os.path.isfile(os.path.join(path, file_name)): img = pg.image.load(path + '/' + file_name).convert_alpha() images.append(img) return images to: def get_images(self, path): images = deque() file_names = natsorted(os.listdir(path)) for file_name in file_names: if os.path.isfile(os.path.join(path, file_name)): img = pg.image.load(f'{path}/{file_name}').convert_alpha() images.append(img) return images but i'm open to any better alternatives.

It may also be the case that I'm the only one with this issue.

cinder92 commented 1 year ago

@barrymun this fix the issue, thanks for your support

clacount commented 1 year ago

@barrymun thanks so much for this! I found the exact same issue today and I knew it needed to be sorted, but wasn't sure how. Really appreciate it!

barata0 commented 1 year ago

Indeed!

image

But you can use the native sorted

def get_images(self, path):
        images = deque()
        for file_name in sorted(os.listdir(path)):
            if os.path.isfile(os.path.join(path, file_name)):
                img = pg.image.load(path + '/' + file_name).convert_alpha()
                images.append(img)
        return images

Now everybody is really dead :)

image