'TypeError: invalid rect assignment. When assigning .rect.center
As in the title I'm getting "TypeError: invalid rect assignment" On the following line:
bullet.rect.x=player.rect.center
Originally the line was:
bullet.rect.x=player.rect.x
Which worked fine, aside from the bullet is firing from the left not centre. Not a massive drama as I can manually add +7 to player.rect.x but id rather do it in a cleaner way.
Thanks!
Solution 1:[1]
player.rect.center is a tuple and you can't assign a tuple to bullet.rect.x. Assign bullet.rect.x to an int or float (which gets truncated) instead.
You can use the centerx attribute of the player to set the x of the bullet.rect.
bullet.rect.x = player.rect.centerx
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | skrx |
