2
votes

How do I use pygame.sprite.collide_rect?

I want to make a game where if the girl is on ice she'll slide and when she's on ground (which will be another sprite) she won't slide. I was going to use the collision detection from pygame, but I'm not sure how.

Can someone please help me?

Thank you so much

2
Aha! It turns out there is a friction coefficient, something I was unaware of. See stackoverflow.com/questions/8306471/sliding-spritesuser1048917
Have you solved this issue? If any of the answers was of any use to you it would be nice to upvote / accept them! :)mac
I usually don't mess with this, I check collision mathematically. It is less complicated and usually allows your game to run faster.Douglas - 15 year old Pythoner

2 Answers

2
votes

Could you post your code?

From what I gather, what you want is something like this:

if pygame.girl.colliderect(ice.rect):
     girl.slide()
elif pygame.girl.colliderect(ground.rect):
     girl.notslide()
0
votes

There are multiple ways to detect collision in pygame. Including rect, with groups of sprites, etc... In order to find one specific way of collision detection is just a matter of seeing the code you're working with. But with a simple sprite and rectangle you could just use:

if pygame.sprite.collide_rect(girl_sprite, ice):
   slide()
else :
   continue_game()