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
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!!!
Tip. Instead of using a defined color key, set the background to be transparent. image = pygame.Surface((width,height), pygame.SRCALPHA).convert_alpha()
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!)
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 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
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))
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!
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.
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?
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
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
@@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.
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?
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
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.
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...
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?
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.
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 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?
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?
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.
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
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
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))
@@_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.
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...)
Mate ur pygame videos are absolute quality, u explain it so much clearer and better than my university. Big love
Haha glad to hear it!
wait u learn pygame in uni ?????
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
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
Thanks, glad you liked it! :)
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!!!
Just the video I needed! Thanks a lot for your very clear and easy to follow explanations.
You're welcome! Glad you found it useful
Tip. Instead of using a defined color key, set the background to be transparent.
image = pygame.Surface((width,height), pygame.SRCALPHA).convert_alpha()
Thank you this helps a lot
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!)
Thanks brother ❤
THANK YOU MEN!!!
OMG THANK YOU. SPEND WHOLE DAY HOW TO REMOVE BLACK BORDER!!!
Love your videos. Especially the way you run through procedural code before getting into classes it really helped me understand the absolute basics
Thanks, glad to hear it was helpful
Wow, I learnt a lot today. This channel is truly a gem!
Thanks! Glad it was helpful
Excellent tutorial. Well explained, easy to follow. I am off to the next one; animation
Thanks, glad it all made sense!
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
Thank you so much, this makes my game so much faster
Awesome, glad it helped!
As usual good video. And thanks for shooter and platformer tutorial. Now I'm making my own game thanks 😁
Thanks! Look forward to seeing your game :)
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
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)
@@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
Thanks, Russ! Big help!
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
Quite helpful! Thanks.
sprite_sheet = spritesheet.SpriteSheet(sprite_sheet_image)
making code readable is such a glorious endeavor.
Thank you! Very good, going to the next video to animate it
this is so helpful, thank you so much!
Thanks, glad to hear it!
Brilliant Tutorial. Onto The next part!
You have forgotten to say like the video and comment :)))
You are best Jehuuehuue!!
Your video is awesome!
Thanks!
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!
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.
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.
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?
Does anybody know why I get an error saying video system not in initialized
Great video! Consolidates what I learned from your Udemy class for building an RPG with pygame.
Great to hear!
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
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
@@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.
amazing tutorial!
Thanks!
the code seems to be working perfectly but my spritesheet is not displayed.. it keeps showing a black background
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?
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
you could include the width, height and background color key to the SpriteSheet properties, perhaps even scale
FYI he does explain this via OOP at 19:06
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.
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...
How do I put files in the directory so I can code in the sprite in?
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?
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.
i'm having the same problem lol
What can I use as an equivalent to paint on Macbook? Helpful video but I am a (new) Mac user.
I want to use VS Code and this does not really help in how to get a sprite inside the pygame code.
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 :(
Did you figure it out already? You need to install pygame first, check out pygame.org
My Sprites contain black colour and it just breaks the sprite. what am i supposed to do?
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?
how do you do it if your sprite has black in it?
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()
can you use an image which is transparrent beforehand so the sprites don't have the black background?
Yes but you have to add .convert_alpha() to the end of the "pygame.image.load" line so that the transparency is not lost
What app are you using with the Dino images displayed?
I use sublime text for coding and I use GIMP for image editing
@@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?
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!
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?
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.
Hey loved your vid and i wonder what software you used ;)
Hello. I used sublime text editor
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
solved , thanks a lot , great video
image = pygame.Surface((width,height), pygame.SRCALPHA).convert_alpha()
Welcome!
What editor you use for creating sprites..?
He seems to be using microsoft paint
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
how did u run the python file in sublime without a terminal!!
CTRL+B
@@CodingWithRuss thnx
thank you!
You're welcome!
Great !!
Thanks!
it keeps saying "no module named pygame" for me.
I have a short video to explain how to fix that error: th-cam.com/video/0x_MEKr0OJQ/w-d-xo.html
@@CodingWithRuss THANK YOU SO MUCH!!!
What IDE are you using?
Sublime text
@@CodingWithRuss Thank you so much, and thank you for the video!
i like how you say zero
I never noticed 😅
@@CodingWithRuss I didn't mean to offend you I swear
I made the video active image about spritesheet is not

what if you have a lot of rows?
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.
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))
@@_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.
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...)
Still working on it tho...i just needed some tips and idea from u...i hope u reply
Also bro, CONGRATS FOR UR 3000+ Subs!
Im ur fan!
Thanks! I didn't know Spyder doesn't let you use mixer, good to know. Bomberman would be pretty cool!
@@CodingWithRuss Sure, welcome...you always learn everything from everyone someday...
first, plz pin so i can show my brother
thanks
holy shit your monitor is huge
Windows 10 🥵🥵🥵
What app you use for your sprite sheet?
I think I used GIMP to arrange it, but I didn't draw the sprites themselves, they are 3rd party