Pygame——surface.blit()函数
surface.blit()函数在这个 Surface 上绘制一个源 Surface。可以使用 dest 参数定位绘图。 dest 参数可以是表示 blit 左上角位置的一对坐标,也可以是一个 Rect,其中矩形的左上角将用作 blit 的位置。目标矩形的大小不影响 blit。
Syntax : blit(source, dest, area=None, special_flags=0) -> Rect
Parameters:
- Source – Draws a source Surface onto this Surface
- dest – The draw can be positioned with the dest argument.
- area -A Rect can also be passed as the destination and the topleft corner of the rectangle will be used as the position for the blit
Python3
# import pygame module
import pygame
pygame.init()
# width
width = 680
# height
height = 480
#store he screen size
z = [width,height]
# store the color
white = (255, 255, 255)
screen_display = pygame.display
# Set caption of screen
screen_display.set_caption('GEEKSFORGEEKS')
# setting the size of the window
surface = screen_display.set_mode(z)
# set the image which to be displayed on screen
python = pygame.image.load('bg.jpg')
# set window true
window = True
while window:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window = False
# display white on screen other than image
surface.fill(white)
# draw on image onto another
surface.blit(python,(50, 50))
screen_display.update()
pygame.quit()
输出: