Understanding Pygame masks

preview_player
Показать описание
A tutorial on how to use masks in pygame. It can be used for more advanced collisions or filling surfaces/giving them outlines.

(You also get lots of perks)

Social stuff:

Timestamps:
0:00:00 - What are masks?
0:03:05 - Masks with sprite collisions
0:14:53 - Mask collisions without sprites
0:28:15 - Filling a surface / creating an outline
0:50:39 - Coloring overlapping areas with masks

Project files:
Рекомендации по теме
Комментарии
Автор

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!

raydin
Автор

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

Persona-jtqv
Автор

We want more of this kind of game Dev people

alwaysalegend
Автор

How do you not have millions of views... This course was amazing! If you did more content, I'd for sure buy your course.

theadventurousprogrammer
Автор

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!

EpicGamerX
Автор

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 :)

umanglunia
Автор

Its actually scary how much bettert than every other youtuber, you are at explaining pygame problems!

marcusberge
Автор

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!

mikechavannes
Автор

last two min is really difficult part.Thank you so much.Your video is really great

kyawmying
Автор

Great guide, an interesting topic very well explained. Thank you very much for this, you did an amazing job!

iammaxpetrov
Автор

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 :)

Kokoz
Автор

I really wish you got more attention, this content is not 30k- it’s 1mill at least

sylvanfranklin
Автор

О, спасибо тебе за видео!
Смотрел у тебя The ultimate introduction to Pygame и это очень крутой видос, спасибо тебе за него

И да, я знаю, что ты не говоришь по-русски, мне просто хочется написать этот комментарий на родном языке =)

doiman
Автор

Your tutorials are amazing!! Can you do a tutorial on dialog boxes for text based cutscenes? Like in RPG/visual novel games?

jimmyslaughter
Автор

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.

michaelhall
Автор

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

biglak
Автор

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?

anthonydrakefordshadow
Автор

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

VectorByte
Автор

How can I have Collisions between a mask and a spritegroup ( Its An Enemy and Bullets)

pascalbouillon
Автор

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!

dakshdubey