需要帮助来“画”线在Python中(pygame)
我一直在遵循教程来学习 pygame。下面的代码是创建一个绿色的窗口(640 x 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)
ive been following a tutorial to learn pygame. the code below is to make a window (640 by 400) that s green. The program is also exposed to draw a red line across the screen. so far i have not been sucessfull in having the line appear. any suggestions?
#! /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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在display.flip()之前调用draw.line,因为现在您在绘制线条之前将数据从缓冲区复制到显示器。
You need to call draw.line before the display.flip(), as it is now you are copying the data from the buffer to the display before the lines is drawn.
为了使某些功能正常工作,您必须在一开始就将代码更改为:
这可确保您拥有所有必需品并“初始化” pygame。
没有 pygame.init() 它不会“打开”大多数功能
in order for some functions to work you have to change your code at the beginning to:
this makes sure you have all of the essentials and that you "initialize" pygame.
without pygame.init() it wouldn't "turn on" most of the functions