I think that a more performance friendly way of filling the surfaces with color would be to use the "special_flags" argument of Surface.fill() as it will only fill non-transparent pixels with the color that you want. Iterating pixel by pixel might be slow in the context of a bigger game. Great video on masks!
If some are confused what guys are talking about: new_obstacle_surf.set_colorkey((0, 0, 0)) new_obstacle_surf.fill('orange', special_flags=pygame.BLEND_RGBA_MULT) does the same thing as that 'for' loop with 'get_at' and 'set_at' methods, but much more efficiently. Though latter gives you clue about useful get_at / set_at methods.
58:30 In this case, since you want to color only the set bits of a mask, all with the same color, you can simply do it while creating the surface from the mask: new_surf = mew_mask.to_surface(setcolor = 'red') to obtain the same result without checking manually every pixel of the surface, and for those interested, the Mask.to_surface method has a few useful params: - surface: Surface to draw mask onto - setsurface: Use this surface color values to draw set bits - unsetsurface: Use this surface color values to draw unset bits - setcolor: Color to draw set bits - unsetcolor: Color to draw unset bits - dest: Surface destination of where to position the topleft corner of the mask being drawn Btw great video and you genuinely deserve more views
Hey you haven't uploaded in a month but I just wanted to say your tutorials are perfect! Don't give up I am sure your content will be noticed, because you actually explain the code rather than have us remembering and your explanations are excellent!
This is one of the best videos I have seen on masks in pygame. Thank you very much for putting this together. You explained the concepts extremely well!
47:40 - we could also enlarge the mask surface/shrink the original surface and blit with the same center, and that should work I think Great video Clear Code... You are one of my favorite youtubers :)
Quick question: How did you do that at 20:16 where you wrote "offset_" on both sides?? Btw awesome videos, I really enjoy them. Very very helpful too. Especially for a self-taught like me. Keep up the great work and wish you all the best :)
О, спасибо тебе за видео! Смотрел у тебя The ultimate introduction to Pygame и это очень крутой видос, спасибо тебе за него И да, я знаю, что ты не говоришь по-русски, мне просто хочется написать этот комментарий на родном языке =)
So if you take the difference of the top left points of the images before the mask , then if any coordinates of one mask added by the offset equals any point on the other mask it’s overlap after 3 hours this is only logical conclusion I can come too but if the original image has a lot of transparency and one is much smaller it still feels like it doesn’t make sense if it already knows the masks coordinates all the offset is the difference of top left which always equals so how do you calculate which coordinates are within overlap idk all I know is add the masks in overlap and the difference in coordinates
Hi, I have a mask question. Can masks be used for player cosmetic choices and if they can, would this remove the processing burden associated with masks if the mask was not responsible for detecting collisions at all?
Hello Christian, thanks for another excellent video. I combined the masks with your Grand Theft game to keep the car inside the track, which got buggy when the player rotates. How do I fix it? Thanks again
@@TuIipe ok cool! Question 1: how would I add scrolling to the overworld? How would I write save states? How do I make the images and where are the font for the “Level 1, Level 2, etc. and how would I assemble them?
@@mrdc3 Im not the best person to answer these but since no one else has yet Ill try to give you some where to start. 1 I dont know if theres a better way but for scrolling I usually create a variable called scrollX, then, everytime the character is about to leave the screen, I make the character stop walking and add scrollX -speed of the character, at last, for every obejct in the game (enemies, background (it has to be long), partciles) I draw them at their true X +scrollX. 2. I havent done this one in a while but the easiest way I know is to create an empty folder somewhere and save some object with the save information to it, using the pickle library. 3. pygame has font rendering in itself, with fonts that come with pygame, but you can use others you install, Id look for a tutorial but it is rather a simple process to render text on a pygame display. Hope this helped.
@@kelsierii4747 But I still dont know which scroll_x variables to put, I already have it defined in level. I could easily copy it, but for the overworld I would need to replace some variables, that is what I am confused about. I am referring to Clear Code’s mario-style platformer
Bloxy, you should join the Clear Code Discord Server! It has people who can help, when you need it. Try it out: (It is in the description of this video)
do you mean it got slow after a mask collision? Usually a good idea is to do a sprite collision and then a mask one but if you struggle with sprite collisions something else went wrong entirely.
Hi, I was once making a game where I stopped at trying to identify if the screen is colored(other than white) per frame. I was thinking iterate through each pixels per frame but it's making game super heavy. Can this be done in pygame too?
thank you :) Most of the artwork I get from opengameart.org which has a ton of free material (there is an artist called Kenney there that makes really good stuff) and I occasionally also use Adobe Photoshop and Illustrator to make some things myself
Jesus Christ the offset is hard to understand the offset makes literally no sense is it just easy to remember to use the difference of the top lefts ?? Then it can calculate the overlap using the masks and difference of the toplefts
I think that a more performance friendly way of filling the surfaces with color would be to use the "special_flags" argument of Surface.fill() as it will only fill non-transparent pixels with the color that you want. Iterating pixel by pixel might be slow in the context of a bigger game. Great video on masks!
oh damn, I totally forgot that fill also has special flags... that would have been very useful :D
If some are confused what guys are talking about:
new_obstacle_surf.set_colorkey((0, 0, 0))
new_obstacle_surf.fill('orange', special_flags=pygame.BLEND_RGBA_MULT)
does the same thing as that 'for' loop with 'get_at' and 'set_at' methods, but much more efficiently.
Though latter gives you clue about useful get_at / set_at methods.
I dont understand what exactly you would put down for this as the special_flags argument to achieve this. Could you explain?
58:30 In this case, since you want to color only the set bits of a mask, all with the same color, you can simply do it while creating the surface from the mask:
new_surf = mew_mask.to_surface(setcolor = 'red')
to obtain the same result without checking manually every pixel of the surface, and for those interested, the Mask.to_surface method has a few useful params:
- surface: Surface to draw mask onto
- setsurface: Use this surface color values to draw set bits
- unsetsurface: Use this surface color values to draw unset bits
- setcolor: Color to draw set bits
- unsetcolor: Color to draw unset bits
- dest: Surface destination of where to position the topleft corner of the mask being drawn
Btw great video and you genuinely deserve more views
We want more of this kind of game Dev people
How do you not have millions of views... This course was amazing! If you did more content, I'd for sure buy your course.
Hey you haven't uploaded in a month but I just wanted to say your tutorials are perfect! Don't give up I am sure your content will be noticed, because you actually explain the code rather than have us remembering and your explanations are excellent!
Yeah, he is awesome!
last two min is really difficult part.Thank you so much.Your video is really great
Its actually scary how much bettert than every other youtuber, you are at explaining pygame problems!
This is one of the best videos I have seen on masks in pygame. Thank you very much for putting this together. You explained the concepts extremely well!
47:40 - we could also enlarge the mask surface/shrink the original surface and blit with the same center, and that should work I think
Great video Clear Code... You are one of my favorite youtubers :)
good idea to enlarge the surface although that would also remove holes inside the surface.
Super glad you like it :)
Great guide, an interesting topic very well explained. Thank you very much for this, you did an amazing job!
Your tutorials are amazing!! Can you do a tutorial on dialog boxes for text based cutscenes? Like in RPG/visual novel games?
Quick question: How did you do that at 20:16 where you wrote "offset_" on both sides??
Btw awesome videos, I really enjoy them. Very very helpful too. Especially for a self-taught like me. Keep up the great work and wish you all the best :)
I really wish you got more attention, this content is not 30k- it’s 1mill at least
The Cat in the begining looked like spider-mans pet
О, спасибо тебе за видео!
Смотрел у тебя The ultimate introduction to Pygame и это очень крутой видос, спасибо тебе за него
И да, я знаю, что ты не говоришь по-русски, мне просто хочется написать этот комментарий на родном языке =)
Privet
lol thanks to yt translation I can read your comment
Finally a new vid
So if you take the difference of the top left points of the images before the mask , then if any coordinates of one mask added by the offset equals any point on the other mask it’s overlap after 3 hours this is only logical conclusion I can come too but if the original image has a lot of transparency and one is much smaller it still feels like it doesn’t make sense if it already knows the masks coordinates all the offset is the difference of top left which always equals so how do you calculate which coordinates are within overlap idk all I know is add the masks in overlap and the difference in coordinates
I tried to make player mask collide with masks in a list
problem is that the player mask only collides with first mask in the mask list
In part 1 when you add if "pygame.sprite.spritecollide(player.sprite,obstacle,False): (rect detection)" it stops working on the left side of the a.
Hi, I have a mask question. Can masks be used for player cosmetic choices and if they can, would this remove the processing burden associated with masks if the mask was not responsible for detecting collisions at all?
THANK YOU
Great video
Very useful.
How can I have Collisions between a mask and a spritegroup ( Its An Enemy and Bullets)
Hi Clear Code I just wanted to ask so is the whole "shape" of the mask a rectangle with 1s and 0s? By the way your vid is awesome!
yes, the whole shape is still a rectangle, and thank you :)
@@ClearCode Thank you so much, you helped me with my code!!!!
Hello Christian, thanks for another excellent video. I combined the masks with your Grand Theft game to keep the car inside the track, which got buggy when the player rotates. How do I fix it? Thanks again
You would have to create a new mask whenever the player rotates which could be quite performance-intensive. Hope this helps
Why not use the walrus operator instead of calling the mask function twice to print it.
Clear Code, In your previous videos, I asked some additional questions. Could you answer them?
@@TuIipe ok cool!
Question 1: how would I add scrolling to the overworld?
How would I write save states?
How do I make the images and where are the font for the “Level 1, Level 2, etc. and how would I assemble them?
@@mrdc3 Im not the best person to answer these but since no one else has yet Ill try to give you some where to start. 1 I dont know if theres a better way but for scrolling I usually create a variable called scrollX, then, everytime the character is about to leave the screen, I make the character stop walking and add scrollX -speed of the character, at last, for every obejct in the game (enemies, background (it has to be long), partciles) I draw them at their true X +scrollX. 2. I havent done this one in a while but the easiest way I know is to create an empty folder somewhere and save some object with the save information to it, using the pickle library. 3. pygame has font rendering in itself, with fonts that come with pygame, but you can use others you install, Id look for a tutorial but it is rather a simple process to render text on a pygame display. Hope this helped.
@@kelsierii4747 But I still dont know which scroll_x variables to put, I already have it defined in level. I could easily copy it, but for the overworld I would need to replace some variables, that is what I am confused about. I am referring to Clear Code’s mario-style platformer
Bloxy, you should join the Clear Code Discord Server! It has people who can help, when you need it. Try it out: (It is in the description of this video)
@@vivat- That would be a good option!Will do!
Please make a tutorials of ghost game 🙏
Quick question: I tried implenting the sprite collision into my game, but it is really laggy. Any tips?
do you mean it got slow after a mask collision? Usually a good idea is to do a sprite collision and then a mask one but if you struggle with sprite collisions something else went wrong entirely.
@@ClearCode I think I meant mask collision. But don’t we have to always check for collisions when the player is walking on the tiles?
oh you want to create a platformer? For the floor you would need a constant collision check but a rect based one should be fine
Hi, I was once making a game where I stopped at trying to identify if the screen is colored(other than white) per frame.
I was thinking iterate through each pixels per frame but it's making game super heavy.
Can this be done in pygame too?
Did you find the answer?
hi just wanted to know how do u get/make those neat sprites that you use in ur vids can u make a vid for it thanks! (btw love ur vids ♥)
thank you :) Most of the artwork I get from opengameart.org which has a ton of free material (there is an artist called Kenney there that makes really good stuff) and I occasionally also use Adobe Photoshop and Illustrator to make some things myself
@@ClearCode tysm
Excuse me☝️, can't we just make a simple application like Facebook with Pygame😅! Please Suggest me...🙏
28:15
Hi
Jesus Christ the offset is hard to understand the offset makes literally no sense is it just easy to remember to use the difference of the top lefts ?? Then it can calculate the overlap using the masks and difference of the toplefts