I'm trying to move a rectangle that I created in the far top right corner down and to the left. I've commented out the line that's causing the error, which is:
invalid destination position for
blit
# render box to display level
displayfont = pygame.font.SysFont(None, 30)
text = displayfont.render('level', True, (red), (white))
textrect = text.get_rect()
textrect.topright = screen.get_rect().topright
# textrect = textrect.move_ip(-50, -50) #keeps getting invalid destination for blit
screen.blit(text, textrect)
Any suggestions? Thanks in advance!
The method pygame.Rect.move_ip doesn't return any value. It modifies the pygame.Rect object itself.
So after
textrect = textrect.move_ip(-50, -50)
the value of textrect is None.
Further note, that the top right coordinate of a Surface is (widht, 0). If you want to move to the center of the surface, then you have to move in the negative x direction, but in the positive y direction rather than the negative y direction.
To solve your issue it has to be:
displayfont = pygame.font.SysFont(None, 30)
text = displayfont.render('level', True, (red), (white))
textrect = text.get_rect()
textrect.topright = screen.get_rect().topright
textrect.move_ip(-50, 50)
screen.blit(text, textrect)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With