0

So yes i have been making this game for a while know and i have allways done detecting buttons and other clikable objects by using:

defined at start ones:

system1 = pygame.draw.rect(screen, red, (500+spacemove_x, 500+spacemove_y, 40, 35), 0)  ###make rect
this is in loop
if system1.collidepoint(ship_x,ship_y):
    print("hello")

Know that does not work at all? But if i put...

system1 = pygame.draw.rect(screen, red, (500+spacemove_x, 500+spacemove_y, 40, 35), 0)
if system1.collidepoint(ship_x,ship_y):
    print("hello")

but that works but it keeps bugging the game like that red square keeps blinking on the screen and i dont want system1 = pygame.draw.rect(screen, red, (500+spacemove_x, 500+spacemove_y, 40, 35), 0)to be in loop.

what causes this and why? and how can i fix this?

Community
  • 1
  • 1
cmdtvt
  • 71
  • 1
  • 10
  • BTW: `pygame.draw.rect()` is used for drawing rectangle but pygame has `pygame.Rect()` to keep position and size ie. `my_rect = pygame.Rect(500+spacemove_x, 500+spacemove_y, 40, 35)` and later you can use to draw `pygeme.draw.rect(screen, red, my_rect)` and to check collision `my_rect.collidepoint(ship_x, ship_y)` or `my_rect.colliderect(ship_rect)` – furas Dec 28 '16 at 13:50
  • this part looks good - your problem have to be in different place. – furas Dec 28 '16 at 13:51
  • This kinda helps with the problem but it is quite wierd still i switched `system1 = pygame.draw.rect(screen, red, (500+spacemove_x, 500+spacemove_y, 40, 35), 0)` on loop to `system1 = pygame.Rect(500+spacemove_x, 500+spacemove_y, 40, 35)` and know it does not draw red triangles. – cmdtvt Dec 28 '16 at 14:56
  • `pygame.Rect()` is use only to keep position and size - it doesn't draw rectangle. – furas Dec 28 '16 at 15:02
  • BTW: [example with button](https://github.com/furas/python-examples/tree/master/pygame/button-hover) but it uses class – furas Dec 28 '16 at 15:04
  • 1
    BTW: [example with button using functions](http://stackoverflow.com/a/41365258/1832058) – furas Dec 28 '16 at 16:19

0 Answers0