简体   繁体   中英

Is there a way to take a “screenshot” in pygame, and then save it as a sprite so as to reduce code complexity?

The title says it all, although in my instance, the reason I wish to use this feature is I plan on having a all this stuff moving around, until I call this "dialogue()" function, when everything will stop, and I will have dialogue options moving about the screen. However, I don't want to continually render everything in the background, so is there some way of going about taking a screenshot in pygame?

You can capture the contents of the Pygame.Surface by making a copy with screen.copy() then when you want to redraw you use screen.blit(copy, (0,0)) . And then you draw on top of that.

Another option is to change your code so that you render the background into a separate surface rather than copying it from the screen and then combine the foreground with the dialogue with it by bliting the background and then the foreground to the screen.

If this isn't right for you, please share more about your program. I haven't used Pygame in a while so this is mostly based on the documentation https://www.pygame.org/docs/ref/surface.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM