bluesplay106
bluesplay106

Reputation: 37

Pygame Collision

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

Upvotes: 2

Views: 894

Answers (2)

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

Upvotes: 0

user1048917
user1048917

Reputation: 411

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

Upvotes: 2

Related Questions