#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Pygame collision detection


    hi everyone, I am working on a quite simple game in pygame.
    it involves a ball which you control jumping over a whole load of other balls in very basic terms.

    I am trying to make the screen go black when your character hits another ball

    I am using this line:

    Code:
    if pygame.sprite.spritecollide(myPlayer, ballGroup, False):
            Surface.fill(BLACK)
    in my while loop to detect the collision but whenever I play the game the screen goes black instantly
    I have done some print checks and it definetly thinks the collision has happend when it hasn't

    I have also tried things like:

    Code:
    pygame.sprite.collision_rect()
    Code:
    pygame.sprite.collision_circle
    but I just get errors.
    WHATS HAPPENING????

    thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    43
    Rep Power
    2
    edit: Pretty sure my answer was incorrect after looking over it, so I deleted the bad advice. I will have to download pygame and experiment.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    well... I dont think it was completely wrong. I tried it and though I didn't
    get a black screen the colision didn't seem to detect, the balls just went past it. Anyway thanks for trying maybe someone else can build on it.

    for anyone else looking ar this the code which I tried was

    Code:
    if pygame.spritecollision(myPlayer, ballGroup, True):
        Surface.fill(BLACK)

IMN logo majestic logo threadwatch logo seochat tools logo