What is a good way to draw images using pygame?

一曲冷凌霜 提交于 2019-12-29 06:14:52

问题


I would like to know how to draw images using pygame. I know how to load them. I have made a blank window. When I use screen.blit(blank, (10,10)), it does not draw the image and instead leaves the screen blank.


回答1:


This is a typical layout:

myimage = pygame.image.load("myimage.bmp")
imagerect = myimage.get_rect()

while 1:
    your_code_here

    screen.fill(black)
    screen.blit(myimage, imagerect)
    pygame.display.flip()



回答2:


import pygame, sys, os
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((100, 100))

player = pygame.image.load(os.path.join("player.png"))
player.convert()

while True:
    screen.blit(player, (10, 10))
    pygame.display.flip()

pygame.quit()

Loads the file player.png. Run this and it works perfectly. So hopefully you learn something.




回答3:


After using blit or any other update on your drawing surface, you have to call pygame.display.flip() to actually update what is displayed.



来源:https://stackoverflow.com/questions/8873219/what-is-a-good-way-to-draw-images-using-pygame

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