Reputation: 391
I am making a simple graphical game in pygame. I wanted to draw 2 rectangles but it only draws one not the other.
I made a class of drawing different figures. To fix that issue I removed the class and made a plain function. Id didn't work too. Then I just put the code of function statements in the program.
The final code I get is this
import pygame
black = (0,0,0)
yellow = (200,200,0)
def drawShopButton():
pygame.draw.rect(gameDisplay, black, (690,435,110,65))
pygame.display.update()
pygame.draw.rect(gameDisplay, yellow, (0,500,110,65))
pygame.display.update()
pygame.init()
gameDisplay = pygame.display.set_mode((800, 500))
gameDisplay.fill((40, 120, 0))
pygame.display.update()
pygame.draw.rect(gameDisplay, black, (690,435,110,65))
pygame.display.update()
clock = pygame.time.Clock()
clock.tick(40)
pygame.draw.rect(gameDisplay, yellow, (0,500,110,65))
pygame.display.update()
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
pygame.display.update()
Upvotes: 1
Views: 718
Reputation: 226
The left top corner of the game board is (0,0) and the bottom right corner is (800,500).
So, pygame.draw.rect(gameDisplay, yellow, (0,500,110,65))
is trying to draw a rectangle that is starting at the right top of the board and is (110, 65) wide and tall.
Your code is drawing two rectangles alright, but beyond the visibility scope.
Upvotes: 2