Library for manage sprite sheet, and pallax background
Project description
This librairy contain so far 3 classes
ParallaxBackground :
This class allows you to automate the parallax effect. It is possible to stack background images and classify displays on the screen allowing continuous scrolling to the right or left. Each layer scrolls at an increasing speed the closer you get to the top of the stack.
Example:
win = pygame.display.set_mode((800, 447))
background = ParallaxBackground()
background.add_background(Path("bg0.png"))
background.add_background(Path("bg1.png"))
background.add_background(Path("bg2.png"))
#by default speed is 5, but you can
# ex: background.speed = 4
while(run):
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
# -1 for left scrolling or 1 for right scrolling
if keys[pygame.K_LEFT]:
background.update(-1)
elif keys[pygame.K_RIGHT]:
background.update(1)
else:
background.update(0)
background.draw(win)
pygame.display.update()`
SpriteSheet :
This class simplifies the use of sprite sheets to produce animations. For a sprite sheet it is possible to extract an image at a position by its column, row. The class also allows you to extract images from the sprite sheet dna an iterable list
Example:
win = pygame.display.set_mode((800, 447))
#for a sprite sheet of images 90px X 90px on 2 rows and 5 columns
sprites = SpriteSheet(Path("chess_set.png"), 90, 90, 2, 5)
while(run):
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
x = 0
sprite:Surface
for sprite in sprites.get_sprite_list():
win.blit(sprite, (x,0))
x += sprite.get_width()
pygame.display.update()
_AnimatedObject :
Automate process for animated objects. With the help of a SpriteSheet, You can define set of action and define set of image for animation. To switch between animation sequence use the method to set action. When an animation ended an event triggered.
Example:
win = pygame.display.set_mode((800, 447))
#for a sprite sheet of images 90px X 90px on 2 rows and 5 columns
sprites = SpriteSheet(Path("chess_set.png"), 90, 90, 2, 5)
player = AnimatedObject(sprites.get_sprite_list(), 1)
player.add_action("run", -1, 8, 15)
player.add_action("jump", 0, 1,7)
player.add_action("begin_slide", 0, 16, 17)
player.add_action("end_slide", 0, 17, 20)
player.add_action("dead", -1, 0, 0)
player.set_action("run")
while(run):
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#Adjust position to new coordinates (EX: move to the right)
player.pos.x += .2
player.update(player.pos)
player.draw(win)
pygame.display.update()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pygametoolsbox-1.2.2.tar.gz
.
File metadata
- Download URL: pygametoolsbox-1.2.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaf76e390c610bb7ff179e9ed069e68752d1af1a75c9dbc2cdfbba530e6f4254 |
|
MD5 | 68daadcc2691132338e48a42f0227b1e |
|
BLAKE2b-256 | 02bf05f80ef67a56834b53c96669efead1b595b02fc6480d845c95bdd905ec17 |
File details
Details for the file PygameToolsBox-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: PygameToolsBox-1.2.2-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4477825a99342174f90a45ec272ab1e9f3cf6c6582d57d0d041e3b7c56b4b4b9 |
|
MD5 | 43ffce85698caadb6e639706d3e67c70 |
|
BLAKE2b-256 | 2237ace27e081a0592bd9e13ee6f71f76840c1ad2189f0277ec4b68dc264498f |