pygame.surface.fill
时间: 2023-06-13 18:08:59 浏览: 95
pygame.surface.fill() 是 Pygame 库中 Surface 对象的一个方法,用于将 Surface 对象填充为指定的颜色。
语法如下:
```python
Surface.fill(color, rect=None, special_flags=0) -> Rect
```
参数说明:
- color:填充颜色,可以是 RGB 或 RGBA 值,也可以是一个 Pygame 颜色对象。
- rect:可选参数,指定要填充的矩形区域,如果不指定则默认填充整个 Surface。
- special_flags:可选参数,指定特殊的填充标记。默认为 0。
返回值:返回被填充的矩形区域(如果指定了 rect 参数)。
示例代码:
```python
import pygame
pygame.init()
# 创建一个 800x600 的窗口
screen = pygame.display.set_mode((800, 600))
# 创建一个红色的 Surface
red_surface = pygame.Surface((400, 300))
red_surface.fill((255, 0, 0))
# 将红色的 Surface 填充到窗口上
screen.blit(red_surface, (200, 150))
# 刷新窗口
pygame.display.flip()
# 等待退出
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
```
运行结果如下:
![pygame.surface.fill() 示例结果](https://cdn.jsdelivr.net/gh/Tommy-Lim/tuchuang/img/20211009153053.png)