Pygame 绘制矩形 [英] Pygame Drawing a Rectangle

查看:38
本文介绍了Pygame 绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个需要知道如何在 python 3.2 中绘制矩形的游戏.

Im making a game that requires knowing how to draw a rectangle in python 3.2.

我检查了很多来源,但没有一个确切地说明如何去做.

I have checked lot of sources but none show exactly how to do it.

谢谢!

推荐答案

import pygame, sys
from pygame.locals import *

def main():
    pygame.init()

    DISPLAY=pygame.display.set_mode((500,400),0,32)

    WHITE=(255,255,255)
    BLUE=(0,0,255)

    DISPLAY.fill(WHITE)

    pygame.draw.rect(DISPLAY,BLUE,(200,150,100,50))

    while True:
        for event in pygame.event.get():
            if event.type==QUIT:
                pygame.quit()
                sys.exit()
        pygame.display.update()

main()

这将创建一个 500 x 400 像素的白色简单窗口.窗口内将出现一个蓝色矩形.您需要使用 pygame.draw.rect 来解决这个问题,并添加 DISPLAY 常量以将其添加到屏幕上,变量 blue 使其变为蓝色(blue 是一个元组,它的值等同于 RGB 值中的蓝色及其坐标.

This creates a simple window 500 pixels by 400 pixels that is white. Within the window will be a blue rectangle. You need to use the pygame.draw.rect to go about this, and you add the DISPLAY constant to add it to the screen, the variable blue to make it blue (blue is a tuple that values which equate to blue in the RGB values and it's coordinates.

查找 pygame.org 了解更多信息

这篇关于Pygame 绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆