0

I have an image of a car. I want it to stay inside the game window when I move it around. But it seems like there's an invisible extension to the top and the left. I use KEYUP and KEYDOWN events to set the flags true or false. I expected this code to work:

if car_r and red_rect.right < screen_rect.right:
        red_rect.centerx += 10
    if car_l and red_rect.left > screen_rect.left:
        red_rect.centerx -= 10
    if car_u and red_rect.top > screen_rect.top:
        red_rect.centery -= 10
    if car_d and red_rect.bottom < screen_rect.bottom:
        red_rect.centery += 10

but instead I had to correct it to work properly:

if car_r and red_rect.centerx + 64 < screen_rect.right:
        red_rect.centerx += 10
    if car_l and red_rect.centerx > screen_rect.left:
        red_rect.centerx -= 10
    if car_u and red_rect.centery > screen_rect.top:
        red_rect.centery -= 10
    if car_d and red_rect.centery + 130 < screen_rect.bottom:
        red_rect.centery += 10

What am I missing here?

F3KDOM
  • 21
  • 1
  • Would recommend replacing your "magic numbers" (10, 130, 64, etc) with named values (REC_WIDTH, REC_HEIGHT, etc). That will make it much easier to debug your issues. – blackbrandt Aug 04 '22 at 13:19
  • Have you checked the image in a paint program like GIMP to see if is properly cropped? There could be some empty space around the car in the image file. – 001 Aug 04 '22 at 13:19
  • There is some transparent space but it's not asymmetrical like it behaves. And I used .convert_alpha() to remove it. – F3KDOM Aug 04 '22 at 13:30
  • Maybe your image have transperant background that you dont now you can try to crop it. – Sarper Makas Aug 14 '22 at 20:30

0 Answers0