|
| 1 | +# Python Pygame Loader |
| 2 | + |
| 3 | +[](https://github.com/kerodekroma/python-pygame-loader/actions/workflows/build_pygame.yml/badge.svg) |
| 4 | + |
| 5 | +This is the demo of the loader of python and pygame. LIVE DEMO LINK: |
| 6 | + |
| 7 | +## Install Dependencies |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install pygame pygbag |
| 11 | +``` |
| 12 | + |
| 13 | +## Run the demo |
| 14 | + |
| 15 | +Once you download this repo and their dependencies are available, run this command |
| 16 | + |
| 17 | +```bash |
| 18 | +python main.py |
| 19 | +``` |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +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: |
| 24 | + |
| 25 | +```py |
| 26 | +from atlas_spritesheet import AtlasSpritesheet |
| 27 | +``` |
| 28 | + |
| 29 | +Then you can just declare the proper class with the asset when your game starts |
| 30 | + |
| 31 | +```py |
| 32 | + file_path = 'assets/python-pygame-loader/python-pygame-loader' |
| 33 | + ''' |
| 34 | + this constructor method needs 3 params: |
| 35 | + - the .png file where is located the spritesheet of the animation |
| 36 | + - the .json file where is located the metadata of the spritesheet |
| 37 | + - the scale of the sprite, you can reduce/enlarge the sprite |
| 38 | + ''' |
| 39 | + loader_spritesheet = AtlasSpritesheet(f'{file_path}.png', f'{file_path}.json', 4) |
| 40 | + ''' |
| 41 | + the `setup` method needs 3 params: |
| 42 | + - the coords to show the animation |
| 43 | + - the frame rate of it, or how many FPS must run the animation itself |
| 44 | + - If the animation must be repeated or not |
| 45 | + ''' |
| 46 | + self.loader_spritesheet.setup((0, 0), 20, True) |
| 47 | +``` |
| 48 | + |
| 49 | +Finally, you can play the animation it into the game loop: |
| 50 | + |
| 51 | +```py |
| 52 | + loader_spritesheet.play(my_main_creen) |
| 53 | +``` |
0 commit comments