Masks (and Pixel-Perfect Collisions) - Pygame Tutorial

Ғылым және технология

Masks are one of the more advanced tools that Pygame provides. They allow you to do all sorts of special graphical effects and mathematical calculations such as per-pixel collisions.
Related Pygame Documentation:
www.pygame.org/docs/ref/mask....
Code Written in Video:
dafluffypotato.com/static/scr...
Patreon:
/ dafluffypotato
Discord:
/ discord
Potato Tier Patrons:
f0ursqu4r3
Abeastsgaming
Agent Effe
Chris Birster
Dale Topley
Eivind Teig
GaryTMSFruitcake
kirat=1
MiggyDoes
Levi Jeske
Hafizur Rahman
laurent
#python #pygame #gamedev

Пікірлер: 68

  • @boki2838
    @boki2838 Жыл бұрын

    I don't know why but every time I watch one of his videos I get inspiration to continue working on my own pygame projects. I really wish more people knew about this chanel.

  • @majestyhype9605

    @majestyhype9605

    Жыл бұрын

    Ikr

  • @Blue-Robin

    @Blue-Robin

    Жыл бұрын

    100%

  • @john-coding
    @john-coding Жыл бұрын

    You are the first person i have seen create tutorials with such depth yet simplicity, from someone like me who has only scraped the surface of pygame am amazed by these intricate and useful features, you really explain it well

  • @brando3465

    @brando3465

    Жыл бұрын

    couldnt have said it better

  • @onogrirwin
    @onogrirwin11 ай бұрын

    In my software renderer I did pixel perfect collisions in the same way that you might do depth buffering. I made an int array the size of the window, initialized to 0, called ID buffer. Then when I render anything, of course I change the RGB of the screen pixel buffer and put the Z in the depth buffer, but I also update the ID buffer. Now when you want to know what objects are on a given pixel... just check the ID buffer. And remember to clear the buffer at the end/beginning of the loop. pixel perfect, doesn't cost too much memory, fast, and works perfectly for 3d as well.

  • @pie2748
    @pie2748 Жыл бұрын

    Excellent works. Keep it up!

  • @StreakyFly
    @StreakyFly7 ай бұрын

    Great tutorial! Learnt a lot of useful stuff :D

  • @MoradSayed
    @MoradSayed Жыл бұрын

    I wanna thank u, I can't tell u how useful that was to me.

  • @undeadpresident
    @undeadpresident Жыл бұрын

    Thank you for mentioning that this doesn't work in earlier pygame versions. Saved me a lot of time.

  • @SidelongSuggestive
    @SidelongSuggestive Жыл бұрын

    Very cool! Can you calculate the outline outside of the mainloop and then just offset it's x and y to improve performance?

  • @millankumar9245
    @millankumar9245 Жыл бұрын

    I think the chapters might be wrong? (Something about selection sort rather than masks!) Either way the video was very helpful! Also what editor are you using? Looks very slick!

  • @DaFluffyPotato

    @DaFluffyPotato

    Жыл бұрын

    I accidentally copied over chapters from the last video. lol

  • @dakshjaiswal8758

    @dakshjaiswal8758

    Жыл бұрын

    @@DaFluffyPotato Sir i have a IMP question to make

  • @dakshjaiswal8758

    @dakshjaiswal8758

    Жыл бұрын

    May I procced

  • @thesupergamer4535

    @thesupergamer4535

    Жыл бұрын

    atom

  • @peytonwheeler559
    @peytonwheeler559 Жыл бұрын

    Yuh so hyped for a new vid

  • @Nerd0.09
    @Nerd0.09 Жыл бұрын

    Your tutorials are really helpful but can you please make a video on your seamless tree swinging movements?

  • @dicember92
    @dicember92 Жыл бұрын

    Hero's come back!

  • @astec9051
    @astec9051 Жыл бұрын

    hey so a small question, do you have any recommended beginner tutorials that i could use to learn pygame? I have quite a nice knowledge in coding in general (I do a bit of python but i mainly specialize in lua but i wanna learn more of python) I looked over alot of tuts but alot of them arent really detailed so maybe someone that does this on a day to day basis might have some advice

  • @thelittledragon5595

    @thelittledragon5595

    Жыл бұрын

    not the potato, but i recommend codingwithruss. im currently watching his platformer shooter tutorials and they're really easy to understand

  • @astec9051

    @astec9051

    Жыл бұрын

    @@thelittledragon5595 thank you so much, his tutorials are really easy to understand thanks again!

  • @minemoebsie
    @minemoebsie Жыл бұрын

    Hi, what editor do you use? (not video editor but just python editor) I've installed PyCharm but its kinda slow... I'm still using IDLE but the downside of that is that you can't really have more than 2 .py files open cuz then you wont be able to edit it very well...

  • @justjie1008

    @justjie1008

    Жыл бұрын

    That is Atom Editor with the package "Scripts".

  • @mingyi456

    @mingyi456

    Жыл бұрын

    Sadly Atom is being deprecated, so official development and support will stop soon. I used Intellij Idea before, and found the speed to be reasonable, so PyCharm should not be any worse. What are the specs of your computer?

  • @pnaeli2006

    @pnaeli2006

    Жыл бұрын

    I personally use vscode and highly recommend it

  • @izionn6621
    @izionn6621 Жыл бұрын

    How do you know what founction do what, do you know them by heart? I'm just a beginner and I try to understand this aspect of programming

  • @umanglunia2194

    @umanglunia2194

    Жыл бұрын

    Use the documentation, Google etc

  • @justjie1008
    @justjie1008 Жыл бұрын

    can you tell us which theme that is?

  • @eboatwright_
    @eboatwright_ Жыл бұрын

    What color theme is this?

  • @avo-catto187
    @avo-catto187 Жыл бұрын

    What do you think of Python Arcade?

  • @skysurfer_kon1641
    @skysurfer_kon1641 Жыл бұрын

    A new pygame video? Yes! And it's the exact video I need and was searching for?? Yes!!! BUT IT'S BY DAFLUFFYPOTATO?!? YESS!!!!!

  • @subomiatteh9363
    @subomiatteh9363 Жыл бұрын

    Can you do a tutorial to show how to use masks for curved platforms collisions?

  • @DaFluffyPotato

    @DaFluffyPotato

    Жыл бұрын

    Depending on the type of platform, those get implemented with just math rather than using masks.

  • @linuslim3841
    @linuslim3841 Жыл бұрын

    Is it possible to make destructible terrain in pygame?

  • @GoldenAfroZZ

    @GoldenAfroZZ

    Жыл бұрын

    Yes Thank you for coming to my ted talk

  • @_pipok
    @_pipok Жыл бұрын

    It's him! It's the potato man!

  • @CardfightVanja
    @CardfightVanja Жыл бұрын

    This is a great intro. My usual usage of masks is through collidemask. For example if I'm making a bullet hell shmup, the hitbox for the player ship is generally smaller than the sprite, so I first check if a bullet is inside the player sprite with spritecollide and if so, then checking the mask collide. I'm sure there are better ways of handling this, but using masks to fine tune collision only when necessary seems to give decent performance.

  • @thiagosilva9816
    @thiagosilva9816 Жыл бұрын

    "phenomenal"

  • @rafikrizik4722
    @rafikrizik4722 Жыл бұрын

    I dont know why, but I'm having a hard time finding an install for Pygame2, everything is Pygame1.X. Do you happen to have a link I could use to install Pygame2?

  • @Aashvark

    @Aashvark

    Жыл бұрын

    in console "pip install pygame --upgrade"

  • @lodybaguette2487

    @lodybaguette2487

    Жыл бұрын

    just make : py -m pip uninstall pygame py -m pip install pygame Btw, Idk why you have this pygame version but ok

  • @writethatdown100
    @writethatdown100 Жыл бұрын

    Does anybody know of a video tutorial on collision with masks? Not for pygame, but just learning how mask collision works? Like not actual code or anything but explaining the algorithms. So I can learn how to make my own collision. But then again, I guess every language has a library for collision. But I still want to learn how it works.

  • @DaFluffyPotato

    @DaFluffyPotato

    Жыл бұрын

    It’s just a bitwise and.

  • @writethatdown100

    @writethatdown100

    Жыл бұрын

    @@DaFluffyPotato Oh, yeah. that's super simple. idk why I didn't think of that. duh

  • @-LTUIiiin
    @-LTUIiiin Жыл бұрын

    Why do stuff like fighting games still use hitboxes instead of having pixel perfect masks?

  • @DaFluffyPotato

    @DaFluffyPotato

    Жыл бұрын

    idk

  • @writethatdown100

    @writethatdown100

    Жыл бұрын

    probably because hitboxes are way easier to code and they're way faster (I think)

  • @dominicballinger6536

    @dominicballinger6536

    Жыл бұрын

    Think about it. Fighting games need consistency and speed. Using masks would make a basic punch unreliable depending on how the other character is shaped and the distance. And calculating masks for them would be more resource intensive than necessary. Using boxes is faster and you will always hit the opponent no matter how their body curves.

  • @raeisac1991
    @raeisac1991 Жыл бұрын

    I want to install pygame but it's not working

  • @majestyhype9605
    @majestyhype9605 Жыл бұрын

    Please DaFluffyPotato i cant find a good python tutorial make one on yt please!!! I need to get into pygame u give me inspiration

  • @theonlydhruv7888

    @theonlydhruv7888

    Жыл бұрын

    ...here you go kzread.info/head/PLX5fBCkxJmm1fPSqgn9gyR3qih8yYLvMj

  • @spenceabeen
    @spenceabeen Жыл бұрын

    Gonk :]

  • @RoboLaboratory
    @RoboLaboratory Жыл бұрын

    Hello

  • @DevNazmul
    @DevNazmul Жыл бұрын

    please make a game step by step and make video and publish on KZread thats help us lot

  • @LukePeters

    @LukePeters

    Жыл бұрын

    Have you looked at his other videos? He's done this multiple times.

  • @lodybaguette2487
    @lodybaguette2487 Жыл бұрын

    Python 3.7 ...

  • @DaFluffyPotato

    @DaFluffyPotato

    Жыл бұрын

    Yee

  • @allwoundup3574
    @allwoundup3574 Жыл бұрын

    it's pretty funny how unreliable pygames built-in collision detection methods are. I was having a hell of a time getting bullets to collide and ricochet appropriately until I finally just said "fuck it" and wrote my own methods.

  • @michaelpalmer2143

    @michaelpalmer2143

    Жыл бұрын

    I use rect.collidelistall() all the time and never had any problems.

  • @allwoundup3574

    @allwoundup3574

    Жыл бұрын

    @@michaelpalmer2143 you must be using it for very very basic collision detection

  • @dakshjaiswal8758
    @dakshjaiswal8758 Жыл бұрын

    I am first sir

  • @dakshjaiswal8758

    @dakshjaiswal8758

    Жыл бұрын

    Sir i have a important question to ask

  • @dakshjaiswal8758

    @dakshjaiswal8758

    Жыл бұрын

    May I proceed

  • @herre3147

    @herre3147

    Жыл бұрын

    @@dakshjaiswal8758 dude just ask the question you don't have to ask for permission

  • @robin7856

    @robin7856

    Жыл бұрын

    @@dakshjaiswal8758 you cannot proceed

  • @dakshjaiswal8758

    @dakshjaiswal8758

    Жыл бұрын

    @@herre3147 ok

Келесі