如何在pygame中创建rect变量而不绘制它们?

2024-04-18 05:34:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我要做的是给一个变量赋值一个rect,而不在屏幕上绘制它。我在想怎么做。下面是我当前为“myRect”指定一个20x20白色矩形的代码:

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))

Tags: 代码fromrectimportevent屏幕绘制screen
1条回答
网友
1楼 · 发布于 2024-04-18 05:34:56

你用Pygame.Rect游戏公司名称:

myRect = pygame.Rect(20,20,100,200)    # 20 left, 20 top, 100 width, 200 height

参见: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

如果你想给它加上颜色,你可以扩展Rect类。在

相关问题 更多 >