Skip to main content

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

PygameToolsBox-1.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

PygameToolsBox-1.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file PygameToolsBox-1.2.0.tar.gz.

File metadata

  • Download URL: PygameToolsBox-1.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for PygameToolsBox-1.2.0.tar.gz
Algorithm Hash digest
SHA256 473c537ab2f7c8166e89840e1ccc9648de8626edb7f4a76dd584fecd9fc4bed4
MD5 a4b3becf025ee52f41def27638393abf
BLAKE2b-256 0edb5757e842c7e7da5d8febd55470e494c33560ba7f31f0309bfd91f251764d

See more details on using hashes here.

File details

Details for the file PygameToolsBox-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for PygameToolsBox-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03c61971bdd46b36635014b016755d163ecd02fe93cb66880c5c4793d64ffa2f
MD5 a668d0dba9259d7dc2c6bdf67e287afc
BLAKE2b-256 ee67dcc5887822a380638ac2d75a486b121f426782e86d7bceeaa4da9016d42d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page