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.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

PygameToolsBox-1.2.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pygametoolsbox-1.2.1.tar.gz.

File metadata

  • Download URL: pygametoolsbox-1.2.1.tar.gz
  • Upload date:
  • Size: 6.6 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.1.tar.gz
Algorithm Hash digest
SHA256 b7d1bc1d02f03a64a1b9ae7565f4441b33fced5eb30e1d91f0ab29e345d2ebf2
MD5 d9f58cca3ca8a7c1051a83ff692f971e
BLAKE2b-256 052fa75b9310a99ba51fd002cd513ca8fb239f26bc6eaa41c2710a80b38ea5aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for PygameToolsBox-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61b3b3bbf3117c62d52d8754d83ba9d885b595ebf4c41157329242b14ee5abd4
MD5 a6e8b47e3c5164c51daf80c1c2e9775c
BLAKE2b-256 0dd198c66c73a525c10c58a9ac96c5f84ab650f1b31a91a541a6ee57aab2e837

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