PyGame Beginner Tutorial in Python - Loading Spritesheets

Поделиться
HTML-код
  • Опубликовано: 28 дек 2024

Комментарии • 123

  • @CanvasKreps-hp7uz
    @CanvasKreps-hp7uz Год назад +50

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

  • @sylvanfranklin6904
    @sylvanfranklin6904 3 года назад +85

    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

  • @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!!!

  • @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 10 месяцев назад

      Thanks brother ❤

    • @jairomatheus9200
      @jairomatheus9200 9 месяцев назад

      THANK YOU MEN!!!

    • @rav88pl
      @rav88pl 8 месяцев назад

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

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

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

  • @eugeneee4009
    @eugeneee4009 3 года назад +6

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

  • @erikoostveen
    @erikoostveen 11 месяцев назад +2

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

  • @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 Год назад +5

    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 3 месяца назад +1

    Quite helpful! Thanks.

  • @armanmaratuly1349
    @armanmaratuly1349 8 месяцев назад

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

  • @vrajsavani
    @vrajsavani 2 года назад

    Brilliant Tutorial. Onto The next part!

  • @stephenkentperez7705
    @stephenkentperez7705 8 месяцев назад

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

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

  • @smokespekter
    @smokespekter Год назад +1

    this is so helpful, thank you so much!

  • @davivieira3619
    @davivieira3619 3 года назад +2

    Your video is awesome!

  • @Chez_Dude
    @Chez_Dude 8 месяцев назад +1

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

  • @oliverbosworth1045
    @oliverbosworth1045 2 года назад +1

    amazing tutorial!

  • @evagok3698
    @evagok3698 2 года назад

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

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

  • @_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?

  • @Arianart_01
    @Arianart_01 2 месяца назад

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

  • @HalfwayAgain
    @HalfwayAgain 5 месяцев назад

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

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

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

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

  • @TestyCool
    @TestyCool 9 месяцев назад

    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.

  • @xxhoodbunnyxx
    @xxhoodbunnyxx Год назад

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

  • @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?

  • @ImTheRealCam
    @ImTheRealCam Год назад

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

  • @vxxvp2042
    @vxxvp2042 3 года назад +1

    Great !!

  • @Hunter-xz4qu
    @Hunter-xz4qu Год назад

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

  • @congsangnguyen3149
    @congsangnguyen3149 3 года назад +1

    thank you!

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

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

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

  • @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?

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

  • @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!

  • @fastboialex9525
    @fastboialex9525 3 года назад

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

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

  • @ashwins4776
    @ashwins4776 3 года назад

    What editor you use for creating sprites..?

    • @lightenergy17
      @lightenergy17 3 года назад +1

      He seems to be using microsoft paint

  • @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!

  • @krishdoesstuff8541
    @krishdoesstuff8541 8 месяцев назад

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

    • @CodingWithRuss
      @CodingWithRuss  8 месяцев назад

      I have a short video to explain how to fix that error: ruclips.net/video/0x_MEKr0OJQ/видео.html

    • @krishdoesstuff8541
      @krishdoesstuff8541 8 месяцев назад

      @@CodingWithRuss THANK YOU SO MUCH!!!

  • @h3l_l
    @h3l_l 4 месяца назад +1

    i like how you say zero

    • @CodingWithRuss
      @CodingWithRuss  4 месяца назад

      I never noticed 😅

    • @h3l_l
      @h3l_l 4 месяца назад

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

  • @legendrags
    @legendrags 2 года назад

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

  • @MistereXMachina
    @MistereXMachina Год назад

    What IDE are you using?

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

  • @quanvuinh20
    @quanvuinh20 3 года назад

    I made the video active image about spritesheet is not

  • @alperklc7782
    @alperklc7782 7 месяцев назад

    thanks

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

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

  • @small_weiner6486
    @small_weiner6486 11 месяцев назад

    holy shit your monitor is huge

  • @earl.youtube
    @earl.youtube 5 месяцев назад

    Windows 10 🥵🥵🥵

  • @coolmirage6069
    @coolmirage6069 11 месяцев назад

    What app you use for your sprite sheet?

    • @CodingWithRuss
      @CodingWithRuss  11 месяцев назад

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