Understanding Pygame masks

  Рет қаралды 41,964

Clear Code

Clear Code

Күн бұрын

Пікірлер: 58
@raydin9485
@raydin9485 3 жыл бұрын
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!
@ClearCode
@ClearCode 3 жыл бұрын
oh damn, I totally forgot that fill also has special flags... that would have been very useful :D
@StarFury2
@StarFury2 2 жыл бұрын
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.
@wouterbosch4571
@wouterbosch4571 2 жыл бұрын
I dont understand what exactly you would put down for this as the special_flags argument to achieve this. Could you explain?
@Persona-jt4qv
@Persona-jt4qv Ай бұрын
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
@alwaysalegend63
@alwaysalegend63 3 жыл бұрын
We want more of this kind of game Dev people
@theadventurousprogrammer6449
@theadventurousprogrammer6449 2 жыл бұрын
How do you not have millions of views... This course was amazing! If you did more content, I'd for sure buy your course.
@EpicGamerX
@EpicGamerX 2 жыл бұрын
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!
@subarunatsuki1902
@subarunatsuki1902 2 жыл бұрын
Yeah, he is awesome!
@marcusberge8378
@marcusberge8378 2 жыл бұрын
Its actually scary how much bettert than every other youtuber, you are at explaining pygame problems!
@mikechavannes5357
@mikechavannes5357 2 жыл бұрын
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!
@umanglunia2194
@umanglunia2194 3 жыл бұрын
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 :)
@ClearCode
@ClearCode 3 жыл бұрын
good idea to enlarge the surface although that would also remove holes inside the surface. Super glad you like it :)
@kyawmying224
@kyawmying224 10 ай бұрын
last two min is really difficult part.Thank you so much.Your video is really great
@iammaxpetrov
@iammaxpetrov 2 жыл бұрын
Great guide, an interesting topic very well explained. Thank you very much for this, you did an amazing job!
@sylvanfranklin6904
@sylvanfranklin6904 3 жыл бұрын
I really wish you got more attention, this content is not 30k- it’s 1mill at least
@doiman6591
@doiman6591 3 жыл бұрын
О, спасибо тебе за видео! Смотрел у тебя The ultimate introduction to Pygame и это очень крутой видос, спасибо тебе за него И да, я знаю, что ты не говоришь по-русски, мне просто хочется написать этот комментарий на родном языке =)
@ZgavY
@ZgavY 3 жыл бұрын
Privet
@Foxtro
@Foxtro 3 жыл бұрын
lol thanks to yt translation I can read your comment
@param4722
@param4722 3 жыл бұрын
Finally a new vid
@jimmyslaughter6262
@jimmyslaughter6262 3 жыл бұрын
Your tutorials are amazing!! Can you do a tutorial on dialog boxes for text based cutscenes? Like in RPG/visual novel games?
@elainemisteria8309
@elainemisteria8309 3 жыл бұрын
THANK YOU
@Kokoz40
@Kokoz40 2 жыл бұрын
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 :)
@nialninyesiga-og2fq
@nialninyesiga-og2fq 3 ай бұрын
The Cat in the begining looked like spider-mans pet
@ZimmoYT
@ZimmoYT 3 жыл бұрын
Great video
@SkyFly19853
@SkyFly19853 3 жыл бұрын
Very useful.
@anthonydrakefordshadow
@anthonydrakefordshadow 4 ай бұрын
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?
@michaelhall2265
@michaelhall2265 Жыл бұрын
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.
@dakshdubey3852
@dakshdubey3852 2 жыл бұрын
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!
@ClearCode
@ClearCode 2 жыл бұрын
yes, the whole shape is still a rectangle, and thank you :)
@dakshdubey3852
@dakshdubey3852 2 жыл бұрын
@@ClearCode Thank you so much, you helped me with my code!!!!
@big123lak
@big123lak 10 ай бұрын
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
@VectorByte
@VectorByte 8 ай бұрын
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
@pascalbouillon1713
@pascalbouillon1713 2 жыл бұрын
How can I have Collisions between a mask and a spritegroup ( Its An Enemy and Bullets)
@mrdc3
@mrdc3 3 жыл бұрын
Clear Code, In your previous videos, I asked some additional questions. Could you answer them?
@mrdc3
@mrdc3 3 жыл бұрын
@@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?
@kelsierii4747
@kelsierii4747 3 жыл бұрын
@@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.
@mrdc3
@mrdc3 3 жыл бұрын
@@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
@vivat-
@vivat- 3 жыл бұрын
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)
@mrdc3
@mrdc3 3 жыл бұрын
@@vivat- That would be a good option!Will do!
@TasteDaRDX
@TasteDaRDX 3 жыл бұрын
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
@Choco794
@Choco794 11 ай бұрын
You would have to create a new mask whenever the player rotates which could be quite performance-intensive. Hope this helps
@mohammadkamran9727
@mohammadkamran9727 2 жыл бұрын
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 ♥)
@ClearCode
@ClearCode 2 жыл бұрын
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
@mohammadkamran9727
@mohammadkamran9727 2 жыл бұрын
@@ClearCode tysm
@maipaksana1667
@maipaksana1667 2 жыл бұрын
Please make a tutorials of ghost game 🙏
@Cookie-mv2hg
@Cookie-mv2hg 2 жыл бұрын
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?
@subarunatsuki1902
@subarunatsuki1902 2 жыл бұрын
Did you find the answer?
@mohiuddinsyed1684
@mohiuddinsyed1684 3 жыл бұрын
Why not use the walrus operator instead of calling the mask function twice to print it.
@Wall_E-Lego_Edition
@Wall_E-Lego_Edition Жыл бұрын
Quick question: I tried implenting the sprite collision into my game, but it is really laggy. Any tips?
@ClearCode
@ClearCode Жыл бұрын
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.
@Wall_E-Lego_Edition
@Wall_E-Lego_Edition Жыл бұрын
@@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?
@ClearCode
@ClearCode Жыл бұрын
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
@mrdc3
@mrdc3 3 жыл бұрын
Hi
@Mjngg02
@Mjngg02 9 ай бұрын
28:15
@eek9313
@eek9313 2 жыл бұрын
Excuse me☝️, can't we just make a simple application like Facebook with Pygame😅! Please Suggest me...🙏
@big123lak
@big123lak 10 ай бұрын
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
The ultimate introduction to Pygame
3:47:58
Clear Code
Рет қаралды 3 МЛН
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 2,7 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 21 МЛН
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 8 МЛН
Cameras in Pygame
1:13:21
Clear Code
Рет қаралды 123 М.
Breakout in python
3:21:21
Clear Code
Рет қаралды 65 М.
I made Games with Python for 10 Years...
28:52
DaFluffyPotato
Рет қаралды 368 М.
Learning pygame by creating Snake [python tutorial]
2:05:00
Clear Code
Рет қаралды 373 М.
Data Analysis with Python for Excel Users - Full Course
3:57:46
freeCodeCamp.org
Рет қаралды 3,3 МЛН
Masks (and Pixel-Perfect Collisions) - Pygame Tutorial
17:35
DaFluffyPotato
Рет қаралды 22 М.
C Programming Tutorial for Beginners
3:46:13
freeCodeCamp.org
Рет қаралды 14 МЛН
Reinforcement Learning Course - Full Machine Learning Tutorial
3:55:27
freeCodeCamp.org
Рет қаралды 913 М.
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 2,7 МЛН