Anita Bui
Anita Bui

Reputation: 1

Collision not working with different sprites?

I followed a tutorial for a simple runner game using pygame and got it to work. So I went to try it again with my own characters and obstacles that I made. But for some reason, the sprites seem to collide from really far away from each other, which causes the game to end. I'm not sure why this is happening as I'm using the pygame sprite collide. Is it possible the sprites are messed up? I also resized them so I'm not sure if that's contributing to the issue.

I tried putting the sprites right in the other code from the tutorial and the same issue happened.

def collision_sprite():
    if pygame.sprite.spritecollide(player.sprite, obstacle_group, False):
        obstacle_group.empty()
        return False
    else:
        return True

Upvotes: -1

Views: 34

Answers (1)

Tarik
Tarik

Reputation: 11209

As per documentation, "Intersection is determined by comparing the Sprite.rect attribute of each Sprite". Your sprite rect attribute must be wrong.

Upvotes: -1

Related Questions