Pygame Animation with Sprite Sheets

Sdílet
Vložit
  • čas přidán 6. 09. 2024
  • Part of a series using Pygame and my own add-on library, Pygame_functions.
    Get the module here: github.com/Ste...
    And if it's your first time using pygame_functions, start here:
    • Pygame Functions: Gett...

Komentáře • 72

  • @LucasOliveira-fm9wy
    @LucasOliveira-fm9wy Před 4 lety +14

    I love you, just speend 2 hours looking for an way to make the frames work and you show in 5 minutes, thank you.

  • @ammanuelgebreegziabher3379

    This is the most helpful video I've ever come across on CZcams. Thank you so much.

  • @IdunRedstone
    @IdunRedstone Před 4 lety +1

    I just watched a tutorial with more complicated code using a sprite sheet so you split it into evenly sized sections and then load in the column and row etc then I find you can just use a gif as I was going to do originally. Oh well at least I know for the next project, great vid!

  • @user-pu5qd1xz7e
    @user-pu5qd1xz7e Před 4 lety +1

    if anyone is stuck on why something doesn't happen check if you name you're file pygame.py maybe thats whats not working

  • @engdaniels
    @engdaniels Před 3 lety

    Great tutorial. Focus on one thing only and done good.
    PS: You could get the direction and last thing is update frame, in this way you end up where you keyup.
    last_Direction = 0
    while True:
    if clock() > nextFrame: # We only animate our character every 80ms.
    frame = (frame+1)%8 # There are 8 frames of animation in each direction
    nextFrame += 80 # so the modulus 8 allows it to loop
    if keyPressed("num6"):
    last_Direction = 0*8+frame
    elif keyPressed("num2"):
    last_Direction = 1*8+frame
    elif keyPressed("num4"):
    last_Direction = 2*8+frame
    elif keyPressed("num8"):
    last_Direction = 3*8+frame
    changeSpriteImage(testSprite, last_Direction)

  • @akihito8247
    @akihito8247 Před 4 lety +1

    I've never used python and i found this really easy to understand because of you
    thank you man

  • @lasscat9025
    @lasscat9025 Před 4 lety

    this is a lifesaver for my game i spent 3 hours trying to make a time system thank you very much!

  • @hankitnap5076
    @hankitnap5076 Před 5 lety +3

    Many thanks! Looking forward to the scrolling background!

  • @howtodraw2820
    @howtodraw2820 Před 4 lety

    Man... This method is amazing, congratulations

  • @geraldl7172
    @geraldl7172 Před 5 lety +4

    Nice video, how should i do if my sprite sheet is not a single line(I mean an array for example)?

  • @BotonianGamingOfficial
    @BotonianGamingOfficial Před 4 lety +1

    How can I do this if the sprite sheet is multiple rows?

  • @3arezu
    @3arezu Před 6 měsíci

    cool video! thanks

  • @disdis6127
    @disdis6127 Před 3 lety

    Hi, please make a series on making a RPG game

  • @thelonesomewanderer2941
    @thelonesomewanderer2941 Před 5 lety +4

    Great video! Could you possibly explain how you made the spritesheet/images for the spritesheet?

    • @PagetTeaches
      @PagetTeaches  Před 5 lety +4

      Well, I didn't draw them! I used the Link sprite sheet (which you can find from various sites). They came in the form of a massive sheet of all the sprites from the game. To make my smaller sprite sheet I just copied each frame that i wanted and arranged them into a long image. (I used the free image editor GIMP for this, but any decent image editor would probably do)
      So long as they are lined up vertically and evenly spaced out horizontally, pygame_functions will split them up appropriately.
      If you have trouble making the sheet, and if you find it easier to just have lots of individual frames in separate images, you can still animate them. Just add them to the sprite using addSpriteImage for each one.

    • @thelonesomewanderer2941
      @thelonesomewanderer2941 Před 5 lety +1

      @@PagetTeaches Brilliant answer, thank you!

  • @theroby27
    @theroby27 Před 5 lety +4

    How do i reduce the size of my sprite? Its very large for the world i have made

    • @PagetTeaches
      @PagetTeaches  Před 5 lety +2

      You should use a graphics editing program to resize and prepare images. I use GIMP, which is free.
      You can resize Sprites using transformSprite, but I would avoid this if you can as it's less efficient.

    • @theroby27
      @theroby27 Před 5 lety

      @@PagetTeachesHow would i change the image size? I tried making the splices smaller inside a big transparent image but it is still appearing 'inlarged' in my game? I use Adobe photoshop

    • @PagetTeaches
      @PagetTeaches  Před 5 lety

      Are you saying you have created a smaller version of the image in Photoshop, but the game is still displaying them large?
      Are you sure you're loading the smaller sprite sheet, instead of the original large one?

    • @theroby27
      @theroby27 Před 5 lety

      @@PagetTeaches yes, i chose the right image also. is there a command that can scale sprites?

    • @PagetTeaches
      @PagetTeaches  Před 5 lety

      @@theroby27 yes, it's transformSprite. github.com/StevePaget/Pygame_Functions/wiki/transformSprite

  • @user-pu5qd1xz7e
    @user-pu5qd1xz7e Před 4 lety

    just subscribed great video my g

  • @marcovirtual
    @marcovirtual Před 4 lety

    If I'm looking for better performance, what is the preferred way of doing sprite animations: a) by importing multiple graphic files, each with a single animation frame, or b) as a single file that contains all the sprite animations?

  • @gamedevnow7551
    @gamedevnow7551 Před 5 lety

    great explanation sir!

  • @islamshare9104
    @islamshare9104 Před 3 měsíci

    bro where can i get that 32 png files

  • @juscapella6649
    @juscapella6649 Před 3 lety

    Hey my images are flickering when I type in "showSprite" any idea why?

    • @PagetTeaches
      @PagetTeaches  Před 3 lety

      By default, the showSprite command updates the whole screen, which can be a bit flickery. To stop this, turn off auto-updating. This video shows you how: czcams.com/video/SA0F6Huj9dg/video.html

    • @juscapella6649
      @juscapella6649 Před 3 lety

      @@PagetTeaches Thank you so much for the quick reply, that worked out perfectly for me!

  • @dutchtimetravelers
    @dutchtimetravelers Před 4 lety

    for me the character won't move, any clue to why this is?

  • @lucasesposito9041
    @lucasesposito9041 Před 4 lety

    Can someone help me please? My code gives me no errors, the game runs, but my sprite doesnt show, even tought I used the showSprite method.

    • @PagetTeaches
      @PagetTeaches  Před 4 lety

      If you post your code on the issues page of the github, I'll take a look

    • @lucasesposito9041
      @lucasesposito9041 Před 4 lety

      @@PagetTeaches wow, I didnt think you would still answer comments here! hahaha thank you, I will post it there!

    • @PagetTeaches
      @PagetTeaches  Před 4 lety

      @@lucasesposito9041 ok, have a look. I've posted a possible fix

  • @jonathanmora8208
    @jonathanmora8208 Před 4 lety

    THIS IS EPIC!!!!!!!

  • @jacobgarwin5616
    @jacobgarwin5616 Před 4 lety

    I am just curious about the format of sprite sheets in general (I am very new to this). The current sprite sheet I am looking at have multiple movement position in the same PNG file. I've also found that finding a Gif of your sprite along with the sheet isn't very common from what I can tell. How are you compensating with these different formats? Is there a way to convert PNG sheet to gif? Can I just feed it the PNG sheet? How do I break up the sheet in to individual smaller frames?

    • @PagetTeaches
      @PagetTeaches  Před 4 lety

      The gif is just a converted PNG. It's not an animated file, so a PNG would work just as well. I got a copy of a sprite sheet, put it into something like GIMP and cut out all the frames I wanted to use. I created a canvas that was 32 times the max width of a frame (I settled on 100 as it doesn't have to be exact) and then spaced each frame at 100px intervals. I seem to remember that when I ran the animation, I had to go back in and shift a few frames by a pixel or two to make it look natural (he bobs up and down when running).
      There are almost certainly tools to make a sprite sheet more efficiently. Pygame could also do with an adjustment to allow you to use a 2D Sheet

  • @ApartmentAngelsFireStarters

    why does my gif show up as a sliver

  • @osf182
    @osf182 Před 5 lety

    Jesus Crist: Thanks dude!!

  • @HannazRolynn
    @HannazRolynn Před 4 lety

    what does this mean?
    line 569, in draw
    surface_blit = surface.blit
    AttributeError: 'str' object has no attribute 'blit

    • @HannazRolynn
      @HannazRolynn Před 4 lety

      do i need to draw a rect or just put image?

    • @HannazRolynn
      @HannazRolynn Před 4 lety

      send help pls

    • @HannazRolynn
      @HannazRolynn Před 4 lety

      ok im fine now

    • @lasscat9025
      @lasscat9025 Před 4 lety

      @@HannazRolynn how do u fix it im having the same issue

    • @HannazRolynn
      @HannazRolynn Před 4 lety

      @@lasscat9025 delete the rect u made and use the sprite no rect

  • @rasberyryboyskaterboy67ska15

    Could you write if the frame is greater than 8 reset it to 0. I hope that makes sense?

    • @PagetTeaches
      @PagetTeaches  Před 4 lety +1

      Two ways:
      If frame > 8:
      frame=0
      Or
      Frame = frame % 8

  • @maxns1031
    @maxns1031 Před 4 lety

    Imported your pygame_functions and have everything. Created a small gif with one 2 frames. But when I try to get the GIF into the project, then it tells me "Pygame.error: No Video mode has been set".. What did I miss?

    • @PagetTeaches
      @PagetTeaches  Před 4 lety

      Making sprites doesn't work until you have created a window with ScreenSize. Did you do that first?

    • @maxns1031
      @maxns1031 Před 4 lety

      Yeah, I did. I’ll look into it a bit more. Mainly working with PyQt5 and matplotlib and other libraries. Just started pygame because I can see that you can both make games and actually apply it to some drone programming.
      Perhaps I scaled or did something wrong with my GIF as I just did some pixel animation in Aseprite..

  • @vilfredogiordano4544
    @vilfredogiordano4544 Před 4 lety

    Hello, whenever I try to implement this in, it comes back with the error: 'NameError: name 'makeSprite' is not defined'. Am I forgetting something here?

  • @elainakhloecockburn7256

    Are you planning to add button function?

    • @StevePagetWorld
      @StevePagetWorld Před 5 lety

      Good point. I know this would be useful. I suspect it would need some tweaks to the events handling of the current version, to allow functions to be attached to buttons.
      I'll look into it.

    • @elainakhloecockburn7256
      @elainakhloecockburn7256 Před 5 lety

      @@StevePagetWorld thanks :)

  • @justsomedude5108
    @justsomedude5108 Před 5 lety

    why every 80ms? trying to understand.

    • @PagetTeaches
      @PagetTeaches  Před 5 lety +1

      The exact number isn't important. But a delay of 80ms means you get 12.5 frames of animation per second, which is roughly what is used in films like classic Disney or Stop Motion animation.

    • @justsomedude5108
      @justsomedude5108 Před 5 lety

      @@PagetTeaches thanks for replying, so basically just play with the number until it matches the animation / character velocity?

    • @PagetTeaches
      @PagetTeaches  Před 5 lety +1

      @@justsomedude5108 yep. If the speed of the feet seems to match the walking speed, that's about right.

  • @SyncRL
    @SyncRL Před 4 lety

    hey my programme is going wayyy toooo fast anybody know anything to slow it down

    • @PagetTeaches
      @PagetTeaches  Před 4 lety +1

      Put a tick(30) command in your main loop to restrict it to 30 frames per second.

    • @SyncRL
      @SyncRL Před 4 lety

      @@PagetTeaches thanks loveyour vids! But also one thing, I am having difficulty making the sprite jump! It sounds simple but please can you tell me the code because I really need it and dont know how to find y coordinate on pygame_functions! You can tell that I am new so please can you help me? one last thing is that i am making a 2D game so there is only going left and right (not up and dow). that is why i need your help! Please help.

  • @rengol.4884
    @rengol.4884 Před 5 lety +1

    Hi I can’t import pygame functions..
    -> Method doesn’t exist.
    Could you please help ? Ty
    Python 3.7 / Pycharm / Pygame

    • @robobros218
      @robobros218 Před 5 lety +3

      Rengo L.
      In the bottom of pycharm there is a button called terminal, click it.
      When in the terminal type:
      Pip install pygame
      Then press enter. If that doesn’t work then idk how to do it.

    • @rengol.4884
      @rengol.4884 Před 5 lety

      Robobros 21 thank you ! I have done this before starting my project. Idk what’s going on, maybe this function has been integrated in another like : from pygame import locals *
      ?

    • @ApartmentAngelsFireStarters
      @ApartmentAngelsFireStarters Před 4 lety

      @@rengol.4884 just do from pygame_functions import * and have the pygame_functions file in the same folder as your script

  • @HannazRolynn
    @HannazRolynn Před 4 lety

    plssss help

  • @fv4202x
    @fv4202x Před 4 lety

    you have no subscribers?

    • @PagetTeaches
      @PagetTeaches  Před 4 lety +2

      Last time I looked I had some! Maybe CZcams is glitching?