Skip to main content
added 94 characters in body
Source Link
DyingIsFun
  • 1.3k
  • 1
  • 17
  • 41

You might want to try directly using the collide_mask() method of the Sprite class. Like you, I have had issues trying to use it as an argument in the spritecollide() method.

AsAlso, as a rule, you should also do regular rectangle collision testing before you test for mask collisions, and only test mask collisions in the event of a rectangular collision. This is because mask collision testing is expensive, but rectangle collision testing is cheap.

I might do something like this:

for sprite in self.game.kill:

    # regular collision check before mask collision check for efficiency
    if self.bounding_rect.colliderect(sprite.bounding_rect):
                                
        # mask collision check
        if pg.sprite.collide_mask(self, sprite):
            self.game.playing = False

You might want to try directly using the collide_mask() method of the Sprite class.

As a rule, you should also do regular rectangle collision testing before you test for mask collisions, and only test mask collisions in the event of a rectangular collision. This is because mask collision testing is expensive, but rectangle collision testing is cheap.

I might do something like this:

for sprite in self.game.kill:

    # regular collision check before mask collision check for efficiency
    if self.bounding_rect.colliderect(sprite.bounding_rect):
                                
        # mask collision check
        if pg.sprite.collide_mask(self, sprite):
            self.game.playing = False

You might want to try directly using the collide_mask() method of the Sprite class. Like you, I have had issues trying to use it as an argument in the spritecollide() method.

Also, as a rule, you should do regular rectangle collision testing before you test for mask collisions, and only test mask collisions in the event of a rectangular collision. This is because mask collision testing is expensive, but rectangle collision testing is cheap.

I might do something like this:

for sprite in self.game.kill:

    # regular collision check before mask collision check for efficiency
    if self.bounding_rect.colliderect(sprite.bounding_rect):
                                
        # mask collision check
        if pg.sprite.collide_mask(self, sprite):
            self.game.playing = False
added 11 characters in body
Source Link
DyingIsFun
  • 1.3k
  • 1
  • 17
  • 41

You might want to try directly using the collide_mask() method of the Sprite class.

As a rule, you should also do regular rectangle collision testing before you test for mask collisions, and only test mask collisions in the event of a rectangular collision. This is because mask collision testing is expensive, but rectangle collision testing is cheap.

I might do something like this:

for sprite in self.game.kill:

    # regular collision check before mask collision check for efficiency
    if self.bounding_rect.colliderect(sprite.bounding_rect):
                                
        # mask collision check
        if pg.sprite.collide_mask(self, sprite):
            self.game.playing = False

You might want to try using the collide_mask() method of the Sprite class.

As a rule, you should also do regular rectangle collision testing before you test for mask collisions, and only test mask collisions in the event of a rectangular collision. This is because mask collision testing is expensive, but rectangle collision testing is cheap.

I might do something like this:

for sprite in self.game.kill:

    # regular collision check before mask collision check for efficiency
    if self.bounding_rect.colliderect(sprite.bounding_rect):
                                
        # mask collision check
        if pg.sprite.collide_mask(self, sprite):
            self.game.playing = False

You might want to try directly using the collide_mask() method of the Sprite class.

As a rule, you should also do regular rectangle collision testing before you test for mask collisions, and only test mask collisions in the event of a rectangular collision. This is because mask collision testing is expensive, but rectangle collision testing is cheap.

I might do something like this:

for sprite in self.game.kill:

    # regular collision check before mask collision check for efficiency
    if self.bounding_rect.colliderect(sprite.bounding_rect):
                                
        # mask collision check
        if pg.sprite.collide_mask(self, sprite):
            self.game.playing = False
Source Link
DyingIsFun
  • 1.3k
  • 1
  • 17
  • 41

You might want to try using the collide_mask() method of the Sprite class.

As a rule, you should also do regular rectangle collision testing before you test for mask collisions, and only test mask collisions in the event of a rectangular collision. This is because mask collision testing is expensive, but rectangle collision testing is cheap.

I might do something like this:

for sprite in self.game.kill:

    # regular collision check before mask collision check for efficiency
    if self.bounding_rect.colliderect(sprite.bounding_rect):
                                
        # mask collision check
        if pg.sprite.collide_mask(self, sprite):
            self.game.playing = False