Skip to content

FranckSix/PygameSpriteTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages