我一直在学习pygame的教程。下面的代码是制作一个绿色的窗口(640×400)。该程序还暴露在屏幕上绘制一条红线。到目前为止,我还没有成功出现这条线。有什么建议吗?
#! /usr/bin/env python
import pygame
screen = pygame.display.set_mode((640, 400))
running = 1
green = 0, 255, 0
red = 255, 0, 0
point1 = 639, 479
point2 = 0, 0
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
screen.fill(green)
pygame.display.flip()
pygame.draw.line(screen, red, point1, point2)
答案 0 :(得分:2)
您需要在display.flip()之前调用draw.line,因为现在您在绘制线条之前将数据从缓冲区复制到显示。
答案 1 :(得分:0)
为了使某些功能起作用,您必须在开头将代码更改为:
import pygame
from pygame.locals import *
pygame.init()
这确保您拥有所有必需品并且您已经初始化" pygame的。 没有pygame.init()它就不会打开"大部分功能