ok this is the best tutorial on masks i've found. so glad i woke to find this tutorial.
@CodingWithRuss
Жыл бұрын
Thanks, glad it was helpful!
@code--breaker
Жыл бұрын
Seriously. I am not speak english but I learned pygame masks and all it is beacuse you.Thanks(maybe I writed wrong sorry.)
@muhammedelzalabany
10 ай бұрын
You are one of the best, other programmers explained this in an hour and you in 10 minutes thank you ❤
@jermania7467
Жыл бұрын
Thanks for tutorial on masks I hadn't really explored them before so this was quite helpful and including the spritecollide logic with the masks. Great content as always!
@CodingWithRuss
Жыл бұрын
Thanks, glad to hear it made sense!
@Daniel-jv6bf
Жыл бұрын
you deserve the oscar, mask collision is exactly what i tried to implement all the time in my games, but always failed, cause I didn't know what to use and how to do it; thanks for stopping my suffering !
@CodingWithRuss
Жыл бұрын
Haha nice, glad to hear it is making sense now.
@CodingWithRuss
Жыл бұрын
For the source code used in this tutorial, head over to my website: www.codingwithruss.com/pygame/how-to-use-pygame-masks-for-pixel-perfect-collision/
@GundirQuid
Жыл бұрын
Thank you, stumbled across this video on one of my late night programming sessions and wanted background audio to listen to. I was using the first method resulting in spaghetti code with many small rectangle checks like you explained before masks, as I was unaware of them actually being a pygame feature. So many wasted lines of code. With this updated knowledge, I have cut down my many lines to just a couple of lines, the code is a lot cleaner to read now as well! Thank you!
@CodingWithRuss
Жыл бұрын
Glad it helped! I've used it in a few of my games as well and it's really good when you need more accurate collision
@NandoDevlop
Жыл бұрын
I'm glad yt recomend me this, this video is awesome
@CodingWithRuss
Жыл бұрын
Thanks!
@TheSteelJackal
Жыл бұрын
You’re fantastic Russ, thank you for these videos!
@CodingWithRuss
Жыл бұрын
Cheers, glad you like them!
@DineshVaidyaOfficial
Жыл бұрын
Thank you so much. I didn't find pygame explanation like you do in any other pygame video tutorial. It was quite helpful. Please keep it on. And i hope you will bring more videos related to pygame with nice examples. Thanks once again.
@CodingWithRuss
Жыл бұрын
Thanks Dinesh, glad this one was useful. I have a few more pygame tutorials in progress :)
@DineshVaidyaOfficial
Жыл бұрын
@@CodingWithRuss Wow! I will be waiting for them. thanks
@lioninaboxgames
11 ай бұрын
This is an amazing tutorial! I wonder which of the two methods are faster and more efficient for getting collision?
@alboukhari20011
Жыл бұрын
As always the best lessons for pygame engine , greate Thinks for all courses
@CodingWithRuss
Жыл бұрын
Thanks, glad you liked it.
@misterelrob
Жыл бұрын
Thank you! Exceptionally clear presentation. You have a new subscriber.
@CodingWithRuss
Жыл бұрын
Thanks! Glad it all made sense.
@SlowPersuit
Жыл бұрын
Excellent work. BTW, as a little "request", do you have any work on 'slopes' for ground? Ive gone through your (great) platformers & OOP'd these with seperate (file) classes, but was wondering about (ground) collision with ramps or slopes- this would make a nice scroller through say a forest (type of scene- following a pathway with up & down gradients), or think of a BMX style game with ramps & jumps (jumps a bit of physics tho!). Hope that makes sense!
@CodingWithRuss
Жыл бұрын
Hi, that's a really good idea for a game! I haven't played around with sloped terrain before but it would be interesting to try. I think it could be quite tricky to implement from scratch although a physics library like pymunk would make it much easier. Thanks for the suggestion, I've added it to my list, although I've already planned out the topics for the next few weeks so this would be something for later down the line.
@lost_hope813
7 ай бұрын
thank you so much! this tutorial helps me to fix my game!😀
@gfgdfgd39
5 ай бұрын
How do I check for collision within it's own sprite group? So one sprite in group A and another sprite also in the same group.
@Qwertyuio010
3 ай бұрын
thanks you for the turorial, but I still have a question, how to use the masks in the full platformer game
@omkarjadhav6049
Жыл бұрын
Really awesome tutorial Russ😍. I am confused 😕 about the optimization of mask collision at 8:55 onwards since both the statements will be executing though??
@CodingWithRuss
Жыл бұрын
Thanks! The optimisation means that the mask check is only executed when there is a rectangle collision, which is quicker and less demanding. So it means that each loop you check for a rectangle collision instead of a mask collision. Only if you get a rect collision, do you then go onto the more demanding check
@omkarjadhav6049
Жыл бұрын
@@CodingWithRuss Got It 👍😊
@omkarjadhav6049
Жыл бұрын
Thanks 👍
@V0LTR0N
9 ай бұрын
i wanted to ask a question. when i try to get a rectangle from my image its always too big and i cant seem to find a way to reduce its size without making errors. the big rectangle means that its difficult to detect collisions as it not accurate. Can you please help?
@CodingWithRuss
9 ай бұрын
It could be that your image has a lot of transparent space around it, which makes it big. You could edit the image to remove the transparent space. Alternatively you can manually define the rectangle instead of using get_rect(). You can define a rectangle using the Rect() class, which you can find here: www.pygame.org/docs/ref/rect.html
@Nitenix
Жыл бұрын
Hi, I love your videos but there’s a bit of code I’m stuck on implementing and I was wondering if there’s any other way I could contact you in order to send it to you
@DaveScurlock
Жыл бұрын
Presumably the second method is better if you have a large number of sprites, so that you can take advantage of sprite groups?
@DaveScurlock
Жыл бұрын
Thanks for a great video btw!
@CodingWithRuss
Жыл бұрын
Yes exactly. Something that you create a lot of instances of and stick into a sprite group would be better suited to the second method.
@droycesendari
Жыл бұрын
Great tutorial!
@CodingWithRuss
Жыл бұрын
Thanks!
@digimonk-ym7br
Жыл бұрын
thanks, you earned a subscriber
@CodingWithRuss
Жыл бұрын
Cheers!
@ShreshthoSaha
Жыл бұрын
Hello sir! I've been watching your tutorials since September 2022. Your videos are really simple and easy to understand. I've learned a lot from those tutorials. I've a problem...when I animate a sprite and check collision between the sprite and an another sprite, the collision happens between the first image of the animating sprite not the other images(frames)! So what's the solution of it?
@CodingWithRuss
Жыл бұрын
I haven't tried but I expect you would just need to update the mask each time you change frames in the animation so then the mask will match the image each time.
@ShreshthoSaha
Жыл бұрын
@@CodingWithRuss you mean animation for the masks too?
@aarohimudholkar6898
7 ай бұрын
Hey! great video and very helpful series. I'm learning very efficiently. One question - what and how does get_rect work?
@michalel
11 ай бұрын
Thank you so much for this tutorial! Now my game isn't full of rectangles xd
@jakeaustin901
9 ай бұрын
Why don't most games (especially fighting games) use such a feature)?
@KeiS14
8 ай бұрын
Skinny characters will get an advantage that’s difficult to account for during the game balancing process
@metrowh4le480
Жыл бұрын
Is it possible to check collision between two sprite groups using masks?
@CodingWithRuss
Жыл бұрын
Yes, you could use the groupcollide() method. I haven't used it but you can find details of it in the docs here: www.pygame.org/docs/ref/sprite.html#pygame.sprite.groupcollide
@ARIADNARB
Жыл бұрын
how can I get pos if I have two oject mooving fandomly? Not specified with mouse
@CodingWithRuss
Жыл бұрын
pos is the x and y coordinate so if you have objects on the screen then you can use their x and y coordinates instead
@ARIADNARB
Жыл бұрын
@Coding With Russ so I can get pos from player_rect and enemy_rect jf I had randomly moving object player and enemy on screen? Do I can het x and y from mask of this objects? Thank you much for answer, you are doing great job with this vodeo - I can create a own game with my 13 old brother! He is happy to do this!
@aronzavoronok8983
Жыл бұрын
can i do it but inside a class?
@CodingWithRuss
Жыл бұрын
Yes I don't see why not.
@kydung5378
6 ай бұрын
Amazing :3333
@khargos7602
6 ай бұрын
👍
@omarsplaytimechannel
Жыл бұрын
5:37 my mask is zoomed in.
@CodingWithRuss
Жыл бұрын
Are you sure you followed the code correctly? Check the link in the description to the full source code that you can check for reference.
@boxhead-zk7sn
Жыл бұрын
sorry but i have pygame.surface(10, 10) ^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'module' object is not callable
@moonlight-hb5df
2 ай бұрын
Capitalize Surface
@zennihilator3724
Жыл бұрын
first
@CodingWithRuss
Жыл бұрын
:)
@АнтонНазарук-щ5с
Жыл бұрын
Hello! Thanks for another brilliant lesson! May I wounder, what is the line "pygame.sprite.Sprite.__init__(self)" do ? Never seen before __init__ inside another __init__
@CodingWithRuss
Жыл бұрын
Thanks Anton, glad you liked it! This is because the Soldier and Bullet classes are being created as child classes of the Sprite class (which already exists in Pygame). This allows me to "inherit" the existing functionality of the Sprite class into the two child classes, but to do this, I need to call the __init__ of the parent class inside them. Difficult to explain in a youtube comment :) So the pygame documentation may be more helpful: www.pygame.org/docs/ref/sprite.html#pygame.sprite.Sprite
Пікірлер: 69