1

I'm currently coding a game for university and I need a sidepanel for that. So I wanted to draw a rectangle on the side. Below you can see my code. We should just use PyGame for everything.

def drawRect():
    rect2 = pygame.Rect(SCREEN_WIDTH - PANEL_SIZE, SCREEN_HEIGHT, PANEL_SIZE, SCREEN_HEIGHT)
    pygame.draw.rect(screen, BLACK, rect2)

The rectangle doesnt pop up on my screen and I just cant figure out why.

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • 1
    Please make sure the indentation of your code in your question is _identical_ to what is in your actual code, because python is sensitive to indentation errors. I prefer to use [code blocks](/help/formatting) with three backticks ( ` ) for this. Since you're new here, please also take the [tour], read [what's on-topic here](/help/on-topic), [ask], and the [question checklist](//meta.stackoverflow.com/q/260648/843953), and provide a [mre]. Welcome to Stack Overflow! – Pranav Hosangadi Jul 28 '21 at 15:47

1 Answers1

1

In the Pygame coordinate system, the top left is (0, 0). Hence, the rectangle at the bottom is off the screen. Change the position of the rectangle:

rect2 = pygame.Rect(SCREEN_WIDTH - PANEL_SIZE, SCREEN_HEIGHT, PANEL_SIZE, SCREEN_HEIGHT)

rect2 = pygame.Rect(SCREEN_WIDTH - PANEL_SIZE, 0, PANEL_SIZE, SCREEN_HEIGHT)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174