1

Greetings,

It seems I am having a bit of trouble with a project I'm working on in pygame. For one of my objects i used:

image.get_rect()

and assigned it to:

self.rect

I understand the default coordinates for the get_rect function gives a value of (0,0). As a result, I used:

self.rect.center = (320,240)

To roughly place the sprite in the middle of the screen. However, later on in a hitTest function, I want to call:

self.rect.colliderect(other_rect)

I get an error: 'tuple' object has no assignment 'colliderect'.

Does this happen because the self.rect.center assignment change the properties of self.rect?

user577317
  • 53
  • 8

1 Answers1

0

The tuple type is immutable. That is, once set, you cannot change it.

I assume that colliderect is trying to modify a tuple.

Use a list in place of that tuple.

Olhovsky
  • 5,466
  • 3
  • 36
  • 47
  • 1
    I see what your saying. I actually found the reason why it wasn't letting me execute the collidepoint module. Earlier in the script I had made self.rect = a tuple, that is why it threw me the error because it assigned self.rect another value(it wasn't a (rect) anymore). Anyway, the self.rect.center call does not effect the status of the rect object. It was a completely different reason why it gave me that error. I appreciate your help, thank you! – user577317 Jan 28 '11 at 05:58