PyGame Beginner Tutorial in Python - Loading Spritesheets

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

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

  • @CanvasKreps-hp7uz
    @CanvasKreps-hp7uz ปีที่แล้ว +48

    Mate ur pygame videos are absolute quality, u explain it so much clearer and better than my university. Big love

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

    It saddens me that channels like this (that give actually good content and get straight to the point) don't get the attention they deserve. My advice is to make really appealing thumbnails

  • @muhammedelzalabany
    @muhammedelzalabany 9 หลายเดือนก่อน +5

    wow so much easier than the other tutorials I've watched five stars ⭐⭐⭐⭐⭐
    you are so calm and just straight in your vids Thank you

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

      Thanks, glad you liked it! :)

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

    I used to sketch characters like Commander Keen onto a post-it note with a grid drawn on it and then redraw them, pixel by pixel, into the Urban Renewal Kit for Sim City when I was a kid. This stuff makes sense-THANK YOU!!!

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

    Just the video I needed! Thanks a lot for your very clear and easy to follow explanations.

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

      You're welcome! Glad you found it useful

  • @wizardly
    @wizardly ปีที่แล้ว +31

    Tip. Instead of using a defined color key, set the background to be transparent.
    image = pygame.Surface((width,height), pygame.SRCALPHA).convert_alpha()

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

      Thank you this helps a lot

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

      Thanks for this! It's comments like these that help cover optimisation areas of coding that are sometimes forgotten by the tutorial creator. (No offence Russ, it was a great tutorial as it was!)

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

      Thanks brother ❤

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

      THANK YOU MEN!!!

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

      OMG THANK YOU. SPEND WHOLE DAY HOW TO REMOVE BLACK BORDER!!!

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

    Love your videos. Especially the way you run through procedural code before getting into classes it really helped me understand the absolute basics

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

      Thanks, glad to hear it was helpful

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

    Wow, I learnt a lot today. This channel is truly a gem!

  • @erikoostveen
    @erikoostveen 10 หลายเดือนก่อน +2

    Excellent tutorial. Well explained, easy to follow. I am off to the next one; animation

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

      Thanks, glad it all made sense!

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

    Dude....
    This will be a great video. Went through this just a week ago on my own...Looking forward to working through it with you

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

    Thank you so much, this makes my game so much faster

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

    As usual good video. And thanks for shooter and platformer tutorial. Now I'm making my own game thanks 😁

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

      Thanks! Look forward to seeing your game :)

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

      I'm commenting here again. While I was making game I got this error
      File: D:\(than it says file location). Line 108 in player_group.draw (screen)
      File: C:\ (it says location again) line 546, in draw surface.blits((spr.image, spr.rect) for spr in sprites)
      TypeError: Source objects must be a surface

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

      I don't know what kind of error it is. I tried to fix it but than it says TypeError: 'Group' can't use blit (I didn't even used .blit function)

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

      @@star_t1 Hard to say what the error is, but it works fine here so must be a typo. Check the code I've linked in the description and it should help find the error

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

    Thanks, Russ! Big help!

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

    Used this to fix issues with images that had black or outlines.
    def get_image(sheet, frame, width, height, scale):
    image = pygame.Surface((width,height), pygame.SRCALPHA).convert_alpha()
    image.blit(sheet, (0,0), ((frame * width), 0, width, height))
    image = pygame.transform.scale(image, (width * scale, height * scale))

    return image

  • @duangaolu
    @duangaolu 2 หลายเดือนก่อน +1

    Quite helpful! Thanks.

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

    sprite_sheet = spritesheet.SpriteSheet(sprite_sheet_image)
    making code readable is such a glorious endeavor.

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

    Thank you! Very good, going to the next video to animate it

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

    this is so helpful, thank you so much!

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

    Brilliant Tutorial. Onto The next part!

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

    You have forgotten to say like the video and comment :)))
    You are best Jehuuehuue!!

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

    Your video is awesome!

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

    Question because I am just learning. Is there a difference between making your while loop with
    Versus
    Is there a performance difference or is it just personal preference? Also, great videos. They are helping me a lot, thank you!

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

      Thanks! It's just personal preference, it's how I saw it done when I was learning pygame so I stuck with it but either option would work.

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

      The first option, saving the run condition to a variable, is prob better, as it lets you to control when you want your game to stop during debugging etc.

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

    Great video! I just picked up pygame to use as part of a school project and am attempting to make a basic game. I'll definitely be passing this link along to others who are interested. I have one question though that's more of a side topic. I am using TIled to create my maps and export as an image and as a csv to track which sprites to draw. So far my tile_ids have line up nicely but I'm hoping someone here may know how to pull tile_ids from a tileset in TIled?

  • @art_made_here
    @art_made_here 8 หลายเดือนก่อน +1

    Does anybody know why I get an error saying video system not in initialized

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

    Great video! Consolidates what I learned from your Udemy class for building an RPG with pygame.

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

    hi, I've pretty much done the code identical, however when I run it at the end it says on line 13 there is a type error: SpriteSheet.__init__() missing 2 required positional arguments: 'columns' and 'rows'.
    I can't identify the issue, please help

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

      It could be that when you are creating the sprite sheet object from your main file, you aren't passing arguments into the brackets. So it is looking for those 2 arguments but it can't find them

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

      @@CodingWithRuss i forgot to say thank you, i fixed that problem. is there anyway you could help me with my collision detection code? i have defined both the sprite_rect and the platform_rect and made the collision detection code but the sprite is not able to jump onto the platforms and goes straight through them. please can you help me as it is my NEA which is due in a couple of days? if i could email you my code or comment it, whatever is best.

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

    amazing tutorial!

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

    the code seems to be working perfectly but my spritesheet is not displayed.. it keeps showing a black background

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

    Great tutorial, but turning the black background transparent also turns all my art that uses the colour black transparent. Do you know how I can fix this?

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

      If you have images with a transparent background, use .convert_alpha() at the end of the image.load() function. This will load the image in and maintain transparency

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

    you could include the width, height and background color key to the SpriteSheet properties, perhaps even scale

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

    FYI he does explain this via OOP at 19:06

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

    You could used get_pixel from the PIL module to sample the color of the top left most pixel. That way you don't need to tell it what the color to make transparent.
    from PIL import Image
    with Image.open('doux.png' **or just image location**) as image
    bad_color = image.get_pixel((0, 0))
    Yes the position needs to be in a tuple so you need the extra parentheses.
    Also Thank god for pygame.transform.scale_by
    just give it a surface and factor and away you go.

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

    followed this but because when you take the file in it makes everything black to transparent any black textures become see through, no explanation of how to change this or what really combines to cause this. and its very common to have black outlines which will be broken...

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

    How do I put files in the directory so I can code in the sprite in?

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

    Hello, Great tutorial. I am having one issue though, after making the spritesheet a standalone class I'm getting the error "SpriteSheet() takes no arguments" coming from the line that creates an object of the class 'sprite_sheet = spritesheet.SpriteSheet(sprite_sheet_image)'. Does anyone know why this might happen?

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

      I had the same problem too. You want to go to spritesheet.py and on Line 4. def __init__(self. image):
      There's two underscores, I missed 1 on each side and that is making the SpriteSheet() takes no argument.

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

      i'm having the same problem lol

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

    What can I use as an equivalent to paint on Macbook? Helpful video but I am a (new) Mac user.

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

    I want to use VS Code and this does not really help in how to get a sprite inside the pygame code.

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

    thanks for the tutorial, now im thinking of making a game, but there is an error that keeps occuring in my code, it says that a module "pygame" does not exist what should i do :(

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

      Did you figure it out already? You need to install pygame first, check out pygame.org

  • @Hunter-xz4qu
    @Hunter-xz4qu 11 หลายเดือนก่อน

    My Sprites contain black colour and it just breaks the sprite. what am i supposed to do?

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

    Could you use a loop to load all the images from the sprite sheet instead of doing it one at a time? and load them into a list?

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

    how do you do it if your sprite has black in it?

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

      just add image.fill((255, 0, 255) or whatever you prefer after "Image = pygame.Surface(). Then choose that same color for the image.set_colorkey()

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

    can you use an image which is transparrent beforehand so the sprites don't have the black background?

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

      Yes but you have to add .convert_alpha() to the end of the "pygame.image.load" line so that the transparency is not lost

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

    What app are you using with the Dino images displayed?

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

      I use sublime text for coding and I use GIMP for image editing

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

      @@CodingWithRuss Thank you! I drew my images using procreate, how would I make a spritesheet from them, would I have to import them to gimp or Microsoft paint?

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

    Thank you very much. Im still having some issues with the sheet i downloaded, which is “indented” by a few picels. This got me somewhere though!

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

    Is it better to make a sprite sheet out of my animations rather than just writing an if loop and loading them into a list of lists? What does it accomplish, because it doesn’t sound any easier? Is it more efficient? Does it save memory?

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

      If your images are already separated into individual frames then I would just stick with that and make a loop to load them into a list of lists. Sometimes when I download 3rd party assets though, they come as complete spritesheets so for those situations this method helps to automatically load the images in.

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

    Hey loved your vid and i wonder what software you used ;)

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

      Hello. I used sublime text editor

  • @SahilTomar-h4c
    @SahilTomar-h4c ปีที่แล้ว

    total noob here, using the color key function is also removing the black outline/details on the asset i am using , can you suggest some fix. thanks in advance

    • @SahilTomar-h4c
      @SahilTomar-h4c ปีที่แล้ว

      solved , thanks a lot , great video
      image = pygame.Surface((width,height), pygame.SRCALPHA).convert_alpha()

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

      Welcome!

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

    What editor you use for creating sprites..?

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

      He seems to be using microsoft paint

  • @boxhead-zk7sn
    @boxhead-zk7sn ปีที่แล้ว

    pls can some one help with this error
    dino_scrpit = image2.Image(dino)
    ^^^^^^^^^^^^^^^^^^
    TypeError: Image.__init__() takes 1 positional argument but 2 were given
    the image2 if the other python file with Image as it class

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

    how did u run the python file in sublime without a terminal!!

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

    thank you!

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

    Great !!

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

    it keeps saying "no module named pygame" for me.

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

      I have a short video to explain how to fix that error: th-cam.com/video/0x_MEKr0OJQ/w-d-xo.html

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

      @@CodingWithRuss THANK YOU SO MUCH!!!

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

    What IDE are you using?

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

      Sublime text

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

      @@CodingWithRuss Thank you so much, and thank you for the video!

  • @h3l_l
    @h3l_l 3 หลายเดือนก่อน +1

    i like how you say zero

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

      I never noticed 😅

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

      @@CodingWithRuss I didn't mean to offend you I swear

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

    I made the video active image about spritesheet is not

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

    what if you have a lot of rows?

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

      It is a bit more tricky then but you could try adding a "for" loop to iterate over the rows and see how that works.

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

      Try something like this... change the signature def get_sprite(self, row, col, width, height, scale, color): .... and then the blit would look like this: img.blit(self.sheet, (0, 0), ((col * width), (row * height), width, height))

    • @Anth.
      @Anth. ปีที่แล้ว

      @@_dotZero_ I know this is really late but, I figured I would put this incase others read this. This does not seem to work,
      gives back Invalid Rect Style Argument. I tried multiple iterations of this. So, idk. If someone else knows how to get this to work, please share here. Thanks in advance if any does.

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

    So nice! I hope you make a bomberman game in PyGame...I tried to do that but I could not load in sound...after some days, I realized that I wasn't using PyCharm, instead, I was using Anaconda...(Note: Anaconda Spyder doesn't support Mixer Module...)

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

      Still working on it tho...i just needed some tips and idea from u...i hope u reply

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

      Also bro, CONGRATS FOR UR 3000+ Subs!

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

      Im ur fan!

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

      Thanks! I didn't know Spyder doesn't let you use mixer, good to know. Bomberman would be pretty cool!

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

      @@CodingWithRuss Sure, welcome...you always learn everything from everyone someday...

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

    first, plz pin so i can show my brother

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

    thanks

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

    holy shit your monitor is huge

  • @earl.youtube
    @earl.youtube 5 หลายเดือนก่อน

    Windows 10 🥵🥵🥵

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

    What app you use for your sprite sheet?

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

      I think I used GIMP to arrange it, but I didn't draw the sprites themselves, they are 3rd party