This is the demo of the loader of python and pygame. LIVE DEMO LINK: https://kerodekroma.itch.io/python-pygame-loader
pip install pygame pygbag
Once you download this repo and their dependencies are available, run this command
python main.py
These steps are part of a single intro of how to add in your code, you can find further details in the main.py
file:
from atlas_spritesheet import AtlasSpritesheet
Then you can just declare the proper class with the asset when your game starts
file_path = 'assets/python-pygame-loader/python-pygame-loader'
'''
this constructor method needs 3 params:
- the .png file where is located the spritesheet of the animation
- the .json file where is located the metadata of the spritesheet
- the scale of the sprite, you can reduce/enlarge the sprite
'''
loader_spritesheet = AtlasSpritesheet(f'{file_path}.png', f'{file_path}.json', 4)
'''
the `setup` method needs 3 params:
- the coords to show the animation
- the frame rate of it, or how many FPS must run the animation itself
- If the animation must be repeated or not
'''
self.loader_spritesheet.setup((0, 0), 20, True)
Finally, you can play the animation it into the game loop:
loader_spritesheet.play(my_main_creen)