PyGame Beginner Tutorial in Python - Sprite Animation

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

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

  • @msrsidehustle
    @msrsidehustle 10 หลายเดือนก่อน +6

    Love how in depth you are explaining this

  • @UrosZbiljic
    @UrosZbiljic ปีที่แล้ว +13

    OH MY GOD. I HAVE BEEN SEARCHING FOR THIS FOR MONTHS! THANK YOU TO THE BOTTOM OF MY HEART!

  • @NeshBlessing
    @NeshBlessing 3 ปีที่แล้ว +27

    Hey Russ I just picked up pygame this week and was in desperate need for beginner tutorials, especially animation. You do a great job with these I appreciate it! Much love ❤️

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว +1

      Awesome, thank you! Glad the videos helped 🙂

  • @veronicapoquette6122
    @veronicapoquette6122 5 หลายเดือนก่อน +3

    Super helpful! I just started using pygame today and I'm already so excited about what I can do with it. Thank you so much for this video!

    • @CodingWithRuss
      @CodingWithRuss  5 หลายเดือนก่อน

      Glad you liked it and good luck with pygame :)

  • @timsousa3860
    @timsousa3860 3 ปีที่แล้ว +11

    How did a 70-views video show up in my recommended?
    Anyways, I'm glad it did! Even though it's not something I was looking for right now it definitely was still interesting and something I'm looking forward to add to my little game! Thanks!

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

      Glad to hear youtube recommendations got it right :)

    • @mtex1024
      @mtex1024 3 ปีที่แล้ว

      I believe in in a saying that, "even the smallest friends can help the biggest." not sure if my spelling is correct, nor the analogy. but hope you understand what I mean.

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

    8:32 in this situation you can write in blit: animation_list[frame%animation_steps]
    For example

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

    Awesome! It was very helpful, thank you Russ.

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

    Dude, your such a fucking G for making this tutorial, I can't wait for my game to be fully coded, with physics and shit.

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

      Haha thanks! Good luck with your game.

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

    Hey , I was on the Third video of your Shooter game. I was a bit confused with Sprites and wanted to watch one video wholly dedicated on it. But I couldn't find the perfect one. What a great Timing. Thank you for Uploading this, I'm gonna watch this first and then Continue the shooter game.
    You contents are DOPE 💥💥.I would love to watch you making a car game with pygame.
    Thanks

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว +2

      Thanks! Good timing :) I plan to make some more of these tutorials which focus on specific tasks like animation, collision etc. After that I will go back to making full game tutorials again

  • @thelastofthemartians704
    @thelastofthemartians704 3 ปีที่แล้ว +2

    Great job with these tutorials, thanks!

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว +1

      No problem! Glad you found them useful.

  • @jamesw8699
    @jamesw8699 2 ปีที่แล้ว +1

    Very helpful. Now I have to figure out how to do this with a grid sprite sheet.

    • @mainakkamakar599
      @mainakkamakar599 2 ปีที่แล้ว +1

      just add a 'y' multiplier too similar to frame*width do, frame*height

  • @msg-1995
    @msg-1995 ปีที่แล้ว +2

    I really like the way you teaching us ❤❤ tq for all of your efforts puting on the video for us👍👍👍

  • @Lucas3D
    @Lucas3D 2 ปีที่แล้ว +1

    Thank you Russ, that was awesome.

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

    you deserve way more views....anyway, thanks a lot for your tutorials

  • @ToujoursIris
    @ToujoursIris 3 ปีที่แล้ว +1

    Im counting on u ;-; You will be de best PyTH-camr

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

    Super helpful! Thank you so much :)

  • @dancronin403
    @dancronin403 3 ปีที่แล้ว +1

    Thanks for making this video!

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว

      You're welcome! Glad it was useful.

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

    Thanks this helped a lot!

  • @artemgrigoriev1150
    @artemgrigoriev1150 3 ปีที่แล้ว +2

    how do you then store this animation code in a player class, to then be able to bind it to "player" and be able to move in the x and y?

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว +2

      I've done that in a few of my games, check out the shooter tutorial as that uses a few animations for the player: th-cam.com/video/DHgj5jhMJKg/w-d-xo.html

  • @zackking5777
    @zackking5777 9 หลายเดือนก่อน

    i use this for 8 directional movement and more, but 4 images in each step and 8 in an animation to spin around and if i move while on a frame above 4 i get error and crash because move images are 1-4

  • @mimiskarafotis4224
    @mimiskarafotis4224 2 ปีที่แล้ว +1

    Please I need your help! How can I put the animation in a rectangle??

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

    Thanks that's really clear and very instructive. But what's the advantages of having a sprite in one big file instead of multiple files that we can just load and not bother with all the positioning part ?

    • @CodingWithRuss
      @CodingWithRuss  ปีที่แล้ว

      It can sometimes be limited to the sprites that you are using, unless you make your own assets. When you get 3rd party asset packs, they are often arranged in spritesheets that you then need to extract your images from.

  • @Endermens_Nikos
    @Endermens_Nikos 3 ปีที่แล้ว +1

    Hi Russ, thanks for your tutorial video, now i'll screw up less)

  • @circuitsparkz
    @circuitsparkz 11 หลายเดือนก่อน

    how could you make it so, if you press a key to play the animation it'll only once until you click that key again?

  • @BlyatifulButter
    @BlyatifulButter 3 ปีที่แล้ว +7

    Hey Russ! May I ask what should I do with multiple spritesheets? I have one for idle animation and one for running but I don't want to merge them together. This is a 5 month old video so I guess you'll never respond but I'll put it out anyway. I appreciate your video though! Great tutorial.

    • @sontoby7309
      @sontoby7309 8 หลายเดือนก่อน

      did you ever figure it out :()

    • @BlyatifulButter
      @BlyatifulButter 8 หลายเดือนก่อน

      @@sontoby7309 if I remember correctly, I did solve it by making the sprite rendering part into a separate function that takes in spritesheets. But again, it’s a 2-year-old issue, so don’t expect a good answer from me.

    • @sontoby7309
      @sontoby7309 8 หลายเดือนก่อน

      @@BlyatifulButter i managed to do it, i just had to do multiple loops and append the temp list to the larger list multiple times

    • @BlyatifulButter
      @BlyatifulButter 8 หลายเดือนก่อน

      @@sontoby7309 good job! Sounds like you can make it cleaner with a recursive function, but if it works, it works alright.

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

    Such a great tutorial! How long you been developing games?

    • @CodingWithRuss
      @CodingWithRuss  2 ปีที่แล้ว +1

      Thank you! I've been working with pygame on and off for a couple years now

    • @JohnnyGrateful
      @JohnnyGrateful 2 ปีที่แล้ว

      @@CodingWithRuss Just curious, do you dev games for a living?

    • @CodingWithRuss
      @CodingWithRuss  2 ปีที่แล้ว

      @@JohnnyGrateful No, not at all, it's just a hobby!

    • @JohnnyGrateful
      @JohnnyGrateful 2 ปีที่แล้ว

      @@CodingWithRuss Cool, its my new favorite hobby! thanks for the help

  • @sontoby7309
    @sontoby7309 8 หลายเดือนก่อน

    does this not work when you have seperate sprite sheets for different actions? ive really been trying to get this to work but cant

  • @wall7312
    @wall7312 3 ปีที่แล้ว +2

    Hi russ, thank you for tutorial, it really helped me, but I have a question: do you think the animation cooldown between frames can be done using a thread function with the wait command?

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว +1

      Thanks, glad it helped! I'm not sure, I haven't tried that but I've always used either a counter variable that I increase at each iteration or just measure the time since the last update.

    • @Endermens_Nikos
      @Endermens_Nikos 3 ปีที่แล้ว

      if you meant returning to the animation after you stop pressing the keys, then I did something similar.

    • @Endermens_Nikos
      @Endermens_Nikos 3 ปีที่แล้ว

      I can send the code from the video with the rollback timer to the animation.

    • @wall7312
      @wall7312 3 ปีที่แล้ว

      @@Endermens_Nikos No, i meant using a thread function that increases the frame number. i paste a part of code here so you can understand what i mean:
      class Player:
      in constructor i define:
      self.thread_cd = threading.Thread(target = self.thread_cooldown)
      then in update method:
      #K_RIGHT
      if (key[pygame.K_RIGHT]) and self.pressed_KRIGHT == False:
      self.animation = True
      try:
      self.thread_cd.start()
      except:
      self.frame = 0
      self.pressed_KRIGHT = True
      elif not (key[pygame.K_RIGHT]):
      self.pressed_KRIGHT = False
      #Immagine
      if self.animation:
      screen.blit(self.frame_list[self.frame], (self.rect.x, self.rect.y))
      else:
      screen.blit(self.frame_list[0], (self.rect.x, self.rect.y))
      self.frame = 0
      thread function:
      def thread_cooldown(self):
      while True:
      wait(40)
      self.frame = self.frame + 1
      if self.frame >= len(self.frame_list):
      self.frame = 0
      self.animation = False
      Probably the code made by Russ is way better than mine but i wanted to try to use a thread function and it actually works.

  • @ElD.Diamond
    @ElD.Diamond 8 หลายเดือนก่อน

    thanks for the video! when I add the update animation part it still only shows me the first frame and doesnt iteratethrough the range but when i tested intitally with the for loop all four frames showed up any idea where im going wrong?

    • @dkonyt1
      @dkonyt1 5 หลายเดือนก่อน

      Same thing is happening to me. Did you fix it? If so, how?

  • @BettercallSaulEditz
    @BettercallSaulEditz 2 หลายเดือนก่อน

    Could someone have another animation on a different sprite sheet? for example one sprite sheet for idle one for running etc

  • @wazmeister3151
    @wazmeister3151 7 หลายเดือนก่อน

    I'm really stuck after undertaking the udmey course (which is fantastic by the way), watching your 2d fighter video and this..... no one seems to cover all alternative animation types. By this I mean, we seen how to extract individual sprites from a large sprite sheet and animate, we've seen how to animate individual sprites... if their with a set number of sprites i.e all sprites only have 4 frames or varied number as this video shows via sprite sheet. But how do we animate sprites for example we have multiple states, i.e Idle, walk, run, attack 1, attack 2 and each state has like 20 individual frames..... another has 24 individual frames etc... How do we code the animation for these type of sprites? Any help is greatly appreciated.

    • @CodingWithRuss
      @CodingWithRuss  7 หลายเดือนก่อน +1

      Hello, I did something like this in my street fighter game. There I had multiple animation types with different numbers of frames. I combined them all into one larger spritesheet using GIMP and then in pygame extracted the different numbers of frames for each animation. This is the link, you can skip through to the part that you need about animation: th-cam.com/video/s5bd9KMSSW4/w-d-xo.html . Hope this helps!

    • @wazmeister3151
      @wazmeister3151 7 หลายเดือนก่อน

      @@CodingWithRuss thanks for response. Yea, problem I ha e it's hard to sometimes combine the sprites together and equally proptioned. Must be a guide how to do it with individual sprites and not just sheets all the time?

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

    It is always fun to see my sprites in other peoples content.

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

      And it's always fun to hear from the original creator :) I really liked these dino sprites, I even started making a side scroller with them at one point but just never got to finish it.

  • @darren-hannahtilly6797
    @darren-hannahtilly6797 3 ปีที่แล้ว

    Hay Russ, first off fantastic tutorials! I am following along trying to create a fairy version for my daughter. However, I am having problems with the collisions with my rectangle, I think it is covering the whole picture frame and not just the image inside. How do I fix this problem?

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว +1

      Thanks, I'm glad you like them. It's hard to explain collision in a comment, but if you use ".get_rect()" on an image it will return a rectangle that covers the whole picture frame as you said. Instead you can manually define a rectangle and give it a size that is more suitable with pygame.Rect(). Hope that helps.

  • @2wen98
    @2wen98 2 ปีที่แล้ว

    hi, this is brilliant, but a random bug popped up that basiccally gives it a permanent afterimage, so to speak. this is an old tutoral, but please help

  • @DG-jq2jq
    @DG-jq2jq หลายเดือนก่อน

    WHERE IS THE LINK TO FIRST TUTORIAL?

  • @diveshkumar8025
    @diveshkumar8025 3 ปีที่แล้ว

    Hi Russ, I want to randomize two things like apple and banana in my snake game but I couldn't find proper solution. Can you please help me.

    • @melonman1252
      @melonman1252 3 ปีที่แล้ว

      Im also a beginner but could you not just import random and then use random.choice( "banana.png","apple.png")

  • @sameersadventures4932
    @sameersadventures4932 3 ปีที่แล้ว

    Whan I load image they say no such file or directory found
    I am using pycharm

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

    weirdly enough mine didnt work until i changed the "if frame >= len(animation_list): to "if frame >= len(temp_image_list)

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

      nevermind, i read ahead. had to add the animation_list[action] portion. im a dingus. hope this helps someone else

  • @MountainMan-j7s
    @MountainMan-j7s หลายเดือนก่อน

    i feel like this could be a optomized. Try making it bit better

  • @itcode2803
    @itcode2803 3 ปีที่แล้ว +1

    cool

    • @CodingWithRuss
      @CodingWithRuss  3 ปีที่แล้ว

      Thanks!

    • @mtex1024
      @mtex1024 3 ปีที่แล้ว

      @@CodingWithRuss this is not cold, so how come you are saying it's cool?

  • @siyo-x
    @siyo-x 6 หลายเดือนก่อน

    This dos not even work for me

  • @sameersadventures4932
    @sameersadventures4932 3 ปีที่แล้ว

    Make more games in pygame

    • @melonman1252
      @melonman1252 3 ปีที่แล้ว

      look at his channel he has so many

  • @geanderson1573
    @geanderson1573 6 หลายเดือนก่อน

    i think you method is too dificult

  • @khargos7602
    @khargos7602 8 หลายเดือนก่อน

    🧑‍💻