I am programming in Python with the pygame library. I want to know how to make a rectangle variable, something like:
import ...
rect1 = #RECT VARIABLE
rect2 = #RECT VARIABLE
Just do
pygame.Rect(left, top, width, height)
this will return you a Rect object in pygame
Perhaps something like this will work?
import pygame
# your whole code until you need a rectangle
rect1 = pygame.draw.rect( (x_coordinate, y_coordinate), (#a rgb color), (#size of rect in pixels) )
If you want a red rectangle with 100x150 size in 0x50 position, it will be:
rect1 = pygame.draw.rect( (0, 50), (255, 0, 0), (100, 150) )
To insert it into the screen you use:
pygame.screen_you_have_created.blit(rect1, 0, 50)
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