Luca Glaentzer
Luca Glaentzer

Reputation: 79

Rectangle doesn't draw

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.

Upvotes: 1

Views: 96

Answers (1)

Rabbid76
Rabbid76

Reputation: 211249

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)

Upvotes: 1

Related Questions