Pygame Animation with Sprite Sheets

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ธ.ค. 2024

ความคิดเห็น • 71

  • @LucasOliveira-fm9wy
    @LucasOliveira-fm9wy 4 ปีที่แล้ว +16

    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
    @ammanuelgebreegziabher3379 4 ปีที่แล้ว +7

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

  • @akihito8247
    @akihito8247 4 ปีที่แล้ว +1

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

  • @lasscat9025
    @lasscat9025 4 ปีที่แล้ว

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

  • @IdunRedstone
    @IdunRedstone 4 ปีที่แล้ว +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!

  • @hankitnap5076
    @hankitnap5076 6 ปีที่แล้ว +3

    Many thanks! Looking forward to the scrolling background!

  • @howtodraw2820
    @howtodraw2820 4 ปีที่แล้ว

    Man... This method is amazing, congratulations

  • @engdaniels
    @engdaniels 4 ปีที่แล้ว

    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)

    • @PagetTeaches
      @PagetTeaches  4 ปีที่แล้ว

      Thanks, dude. Good suggestion!

  • @user-pu5qd1xz7e
    @user-pu5qd1xz7e 4 ปีที่แล้ว +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

  • @geraldl7172
    @geraldl7172 5 ปีที่แล้ว +4

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

  • @BotonianGamingOfficial
    @BotonianGamingOfficial 4 ปีที่แล้ว +1

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

  • @theroby27
    @theroby27 5 ปีที่แล้ว +4

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

    • @PagetTeaches
      @PagetTeaches  5 ปีที่แล้ว +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 5 ปีที่แล้ว

      @@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  5 ปีที่แล้ว

      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 5 ปีที่แล้ว

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

    • @PagetTeaches
      @PagetTeaches  5 ปีที่แล้ว

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

  • @marcovirtual
    @marcovirtual 4 ปีที่แล้ว

    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?

  • @thelonesomewanderer2941
    @thelonesomewanderer2941 5 ปีที่แล้ว +4

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

    • @PagetTeaches
      @PagetTeaches  5 ปีที่แล้ว +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 5 ปีที่แล้ว +1

      @@PagetTeaches Brilliant answer, thank you!

  • @jacobgarwin5616
    @jacobgarwin5616 4 ปีที่แล้ว

    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  4 ปีที่แล้ว

      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

  • @user-pu5qd1xz7e
    @user-pu5qd1xz7e 4 ปีที่แล้ว

    just subscribed great video my g

  • @dutchtimetravelers
    @dutchtimetravelers 4 ปีที่แล้ว

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

  • @lucasesposito9041
    @lucasesposito9041 4 ปีที่แล้ว

    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  4 ปีที่แล้ว

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

    • @lucasesposito9041
      @lucasesposito9041 4 ปีที่แล้ว

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

    • @PagetTeaches
      @PagetTeaches  4 ปีที่แล้ว

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

  • @juscapella6649
    @juscapella6649 4 ปีที่แล้ว

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

    • @PagetTeaches
      @PagetTeaches  4 ปีที่แล้ว

      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: th-cam.com/video/SA0F6Huj9dg/w-d-xo.html

    • @juscapella6649
      @juscapella6649 4 ปีที่แล้ว

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

  • @rasberyryboyskaterboy67ska15
    @rasberyryboyskaterboy67ska15 4 ปีที่แล้ว

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

    • @PagetTeaches
      @PagetTeaches  4 ปีที่แล้ว +1

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

  • @maxns1031
    @maxns1031 5 ปีที่แล้ว

    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  5 ปีที่แล้ว

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

    • @maxns1031
      @maxns1031 5 ปีที่แล้ว

      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 4 ปีที่แล้ว

    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?

    • @TreeFrogOnATree
      @TreeFrogOnATree 4 ปีที่แล้ว

      You have to install and import pygame_functions

  • @disdis6127
    @disdis6127 4 ปีที่แล้ว

    Hi, please make a series on making a RPG game

  • @ApartmentAngelsFireStarters
    @ApartmentAngelsFireStarters 4 ปีที่แล้ว

    why does my gif show up as a sliver

  • @HannazRolynn
    @HannazRolynn 4 ปีที่แล้ว

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

    • @HannazRolynn
      @HannazRolynn 4 ปีที่แล้ว

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

    • @HannazRolynn
      @HannazRolynn 4 ปีที่แล้ว

      send help pls

    • @HannazRolynn
      @HannazRolynn 4 ปีที่แล้ว

      ok im fine now

    • @lasscat9025
      @lasscat9025 4 ปีที่แล้ว

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

    • @HannazRolynn
      @HannazRolynn 4 ปีที่แล้ว

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

  • @SyncRL
    @SyncRL 4 ปีที่แล้ว

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

    • @PagetTeaches
      @PagetTeaches  4 ปีที่แล้ว +1

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

    • @SyncRL
      @SyncRL 4 ปีที่แล้ว

      @@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.

  • @gamedevnow7551
    @gamedevnow7551 6 ปีที่แล้ว

    great explanation sir!

  • @elainakhloecockburn7256
    @elainakhloecockburn7256 5 ปีที่แล้ว

    Are you planning to add button function?

    • @StevePagetWorld
      @StevePagetWorld 5 ปีที่แล้ว

      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 5 ปีที่แล้ว

      @@StevePagetWorld thanks :)

  • @justsomedude5108
    @justsomedude5108 6 ปีที่แล้ว

    why every 80ms? trying to understand.

    • @PagetTeaches
      @PagetTeaches  6 ปีที่แล้ว +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 6 ปีที่แล้ว

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

    • @PagetTeaches
      @PagetTeaches  6 ปีที่แล้ว +1

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

  • @rengol.4884
    @rengol.4884 5 ปีที่แล้ว +1

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

    • @robobros218
      @robobros218 5 ปีที่แล้ว +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 5 ปีที่แล้ว

      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 4 ปีที่แล้ว

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

  • @3arezu
    @3arezu 10 หลายเดือนก่อน

    cool video! thanks

  • @jonathanmora8208
    @jonathanmora8208 4 ปีที่แล้ว

    THIS IS EPIC!!!!!!!

  • @osf182
    @osf182 5 ปีที่แล้ว

    Jesus Crist: Thanks dude!!

  • @HannazRolynn
    @HannazRolynn 4 ปีที่แล้ว

    plssss help

  • @fv4202x
    @fv4202x 4 ปีที่แล้ว

    you have no subscribers?

    • @PagetTeaches
      @PagetTeaches  4 ปีที่แล้ว +2

      Last time I looked I had some! Maybe TH-cam is glitching?