Reputation: 23
What I want to do is assign a rect to a variable without drawing it on the screen. I was wondering how to do this. Here's my current code to assign a 20x20 white rectangle to "myRect":
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((50, 50))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
myRect = pygame.draw.rect(screen, (255, 255, 255), (0, 0, 20, 20))
Upvotes: 2
Views: 1119
Reputation: 51683
You use Pygame.Rect:
myRect = pygame.Rect(20,20,100,200) # 20 left, 20 top, 100 width, 200 height
See: https://www.pygame.org/docs/ref/rect.html
pygame.Rect
pygame object for storing rectangular coordinates
Rect(left, top, width, height) -> Rect
Rect((left, top), (width, height)) -> Rect
Rect(object) -> Rect
If you want to put a color on it as well, you could extend the Rect class.
Upvotes: 3