[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] more collidepoint problems



You're inserting tuples rather than rect objects into the rect array.  Try

newRect = rect.Rect(mouse1x, mouse1y, mouse2x - mouse1x, mouse2y - mouse1y)

--Mike


Eric Hunter wrote:
well at least I'm getting better

here's the error I'm getting now

Traceback (most recent call last):
  File "G:\test2.py", line 40, in <module>
    if box.collidepoint(mousexTEMP, mouseyTEMP):
AttributeError: 'tuple' object has no attribute 'collidepoint'


from this code:


import pygame
from pygame.locals import *

pygame.init()

surface = pygame.display.set_mode ((400, 300))

point_draw = 1

rect = []

rectRect = []

numRect = 0

while True:
        surface.fill((255, 255, 255))
        for event in pygame.event.get():
if event.type == QUIT:
                        pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
                        if event.button == 1:
                                if point_draw == 1:
mouse1x, mouse1y = pygame.mouse.get_pos()
                                        point_draw = 2
                                        # print mouse1x, mouse1y
                                else:
mouse2x, mouse2y = pygame.mouse.get_pos() pygame.draw.rect(surface, ((255, 255, 0)), (mouse1x, mouse1y, mouse2x - mouse1x, mouse2y - mouse1y), 1)
                                        # print mouse2x, mouse2y
                                        numRect += 1
newRect = mouse1x, mouse1y, mouse2x - mouse1x, mouse2y - mouse1y
                                        rect.append(newRect)
                        if event.button == 3:
mousexTEMP, mouseyTEMP = pygame.mouse.get_pos()
                                for i in range(0, numRect):
                                        box = rect[i]
if box.collidepoint(mousexTEMP, mouseyTEMP):
                                                del rect[i]
                                                numRect = numRect - 1

        for i in range(0 , numRect):
                #print i
                pygame.draw.rect(surface, ((255, 255, 0)), rect[i], 1)

        pygame.display.flip()