为什么pygame.draw.shape返回Rect? [英] Why does pygame.draw.shape return a Rect?

查看:122
本文介绍了为什么pygame.draw.shape返回Rect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我知道draw函数的目的是绘制到特定的表面,但我不明白为什么它不能简单地返回pygame.Surface对象,以后可以在需要时将其拉伸到表面.到目前为止,当我只想创建一个曲面并将其绘制到其他物体上时,这一直很不方便.

Although I understand that the purpose of the draw function is to draw to a certain surface, I don't understand why it doesn't simply return a pygame.Surface object that you can later blit to a surface whenever needed. So far this has been very inconvenient when I just want to create a surface and draw it to something else later.

有什么方法可以让您获得类似的功能来返回一个表面对象,而不是执行额外的步骤并直接绘制到另一个表面上?

Is there any way that you can get similar functions to return a surface object, instead of going that extra step and drawing directly to another surface?

推荐答案

要制作具有所需形状的曲面,您可以绘制到另一个曲面,而不是绘制到原始曲面,然后再将其绘制为原始曲面一个.

To make a surface with the shape you want, instead of drawing to the original surface, you draw to another surface and then later you can blit it to the original one.

关于draw函数为何返回rect的原因,它仅用于更新屏幕上需要更新的部分,以便稍后优化代码.这样做的方法是每次要在屏幕上绘制内容时,都将其附加到列表中,然后在更新屏幕时按如下方式进行操作:

As to why the draw functions return a rect, it serves to later optimise your code by only updating the parts of the screen that need to be updated. The way you do this is every time you want to draw something to the screen, you append the rect that it returns to a list and when you go to update the screen you do it like so:

pygame.display.update(rect_list)

这篇关于为什么pygame.draw.shape返回Rect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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