0

I'm completely new to prgramming and python/pygame (and I'm german so please exuse me for the suboptimal english).

Well,

I created a Sprite:

class Holzfaeller_sprite(pygame.sprite.Sprite):
    def __init__ (self, width = 20, height = 20):
        #super(Holzfaeller_sprite, self).__init__()
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface((width, height))
        self.image = pygame.image.load("holzfaeller.png")
        self.rect = self.image.get_rect()

    def set_position(self, x, y):
        self.rect.x = x
        self.rect.y = y

Then I created a group and added the sprite to it:

baut_group = pygame.sprite.Group()
a_Baut = Holzfaeller_sprite()
b_Baut = Festung_sprite()
baut_group.add(a_Baut, b_Baut)

In my gameloop I want to check, if the sprite got clicked on or not with:

elif event.type == pygame.MOUSEBUTTONDOWN and holzfaeller is False and festung is False:
    if a_Baut.rect.collidepoint(possi):
        anklickbar = False
        print("not working")
    elif b_Baut.rect.collidepoint(possi):
        anklickbar = False
        print("not working")
    elif anklickbar is True:
        tilemap_1[possi_y][possi_x] = 0

Well that is working out great but it's gonna be a lot of work and code to add to the line elif event.type == pygame.MOUSEBUTTONDOWN and holzfaeller is False and festung is False.

So I asked my self, if there is a possibility to check if the possition, where I clicked on is a sprite of a specific sprite group.

I hope you understand, what i mean.

Thanks!

cmd
  • 5,754
  • 16
  • 30
Holla
  • 35
  • 1
  • 7
  • 1
    If I understand correctly what you are asking, couldn't you just `any(sprite.rect.collidepoint(possi) for sprite in baut_group.sprites())` or maybe `pygame.sprite.spritecollideany()` if you have a mouse cursor sprite – cmd Oct 02 '15 at 21:16
  • First one worked out perfectly :) Thank you! – Holla Oct 05 '15 at 14:06

0 Answers0