0

I'm making a game and I've made a click and drag system. The only problem is that when I'm dragging it the object (in my case a circle) it is very laggy like a sideshow, but only the circle lags. Below is the function in the class:

def select_func(self):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    if click[0] == 1:
        if self.posX + self.radius > mouse[0] > self.posX - self.radius and self.posY + self.radius > mouse[1] > self.posY - self.radius and self.select is False:
            self.select = True
            while self.select:
                self.posX = mouse[0]
                self.posY = mouse[1]
                for squareNum in range (0, 100):
                    main.square_group.all(squareNum)
                    squareNum += 1
                    main.button(main.new_token, "New Token", main.grey, main.light_grey, main.brown, 800, 0, 200, 100, 22)
                if click[0] == 1:
                    self.select = False
                pygame.display.update()
                main.clock.tick(60)
Orange1861
  • 595
  • 1
  • 4
  • 10
  • in `while self.select` loop you don't run `for event` and `get_pos()` so you could have old data. – furas Feb 12 '16 at 14:35
  • btw: I would say that the code is too complicated – furas Feb 12 '16 at 14:38
  • Furas, I'm not good at programming (This code was self made) so can you propose solutions. – Orange1861 Feb 12 '16 at 15:28
  • simple example (with standard `mainloop`) to drag rectangles http://pastebin.com/cEvjWy9z. For circles you have to change `MOUSEBUTTONDOWN` and draw circles. – furas Feb 12 '16 at 15:41
  • How would I change the MOUSEBUTTONDOWN to draw circles? – Orange1861 Feb 12 '16 at 16:27
  • you have to change `MOUSEBUTTONDOWN` to check mouse collision with circle (using radius, etc.) because `r.collidepoint(event.pos)` check collision with rectangle. – furas Feb 12 '16 at 16:43
  • example with circles and `Pythagoras` instead of `r.collidepoint(event.pos)` http://pastebin.com/9VdUEPXi – furas Feb 12 '16 at 17:04

0 Answers0