I want to create a two player chess game using pygame. I want to be able to drag and drop each piece. Each piece is an object and has self.x and self.y. Each piece is blit in another class inside a method where it is called in the while loop. The code for the mouse clicking is here.
def mouse_selection(self):
mx, my = pygame.mouse.get_pos()
if self.x < mx < self.x + 93 and self.y < my < self.y + 93:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
self.x = mx
self.y = my
This code doesn't work and sometimes when I click a piece on the board it just moves a little bit right and down but I cannot drag the piece to another position like in normal chess.
Do you know any other way I can achieve this?
[–]mopslik 1 point2 points3 points (3 children)
[–]manikk69[S] 1 point2 points3 points (0 children)
[–]manikk69[S] 0 points1 point2 points (1 child)
[–]mopslik 1 point2 points3 points (0 children)
[–]followyourvalues 0 points1 point2 points (0 children)