Why does pygame.draw.shape return a Rect?

喜你入骨 提交于 2019-12-08 04:07:33

问题


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?


回答1:


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.

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)


来源:https://stackoverflow.com/questions/15468472/why-does-pygame-draw-shape-return-a-rect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!