Surface.convert(Surface=None)Surface.convert_alpha(Surface=None) 当我们通过调用pygame.image.load()加载了一张图片并通过blit()函数将其绘制到目标Surface对象上时,如果这张图片的像素格式跟目标Surface对象的像素格式不一致,那么blit()函数就会在内部进行格式转换。 然而,因为blit
importpygame# 导入模块pygame.init()# 初始化模块screen=pygame.display.set_mode((800,600))# 创建一个Surface对象窗口keep_going=True# 循环标志fullscreen=False# 全屏布尔值标志pic=pygame.image.load("logo_lofi.png")# 从文件加载图片whilekeep_going:foreventinpygame.event.get():# 获取事件ifevent.type...
pygame.Surface.get_offset() — 获取子 Surface 对象在父对象中的偏移位置 pygame.Surface.get_abs_offset() — 获取子 Surface 对象在顶层父对象中的偏移位置 pygame.Surface.get_size() — 获取 Surface 对象的尺寸 pygame.Surface.get_width() — 获取 Surface 对象的宽度 pygame.Surface.get_height() — ...
传入一个矩形对象,为了返回实例surface对象中矩形的一部分, 新的surface对象将继承他的父亲,颜色以及透明度设置上都继承了它的父对象 surface.set_at((x,y),color) 设置某一像素位置的颜色 surface.get_at((x,y)) 获得某一像素位置的颜色 surface.get_width() 返回surface对象的宽度 surface.get_height() 返回...
surface.get_width()返回surface对象的宽度 surface.get_height()返回surface对象的高度 mouse模块主要是针对于鼠标事件进行控制 pygame.mouse.get_pos()获得鼠标指针当前的位置,返回的值为元祖类型,即为(x,y),返回值与显示屏的Top-Left值是息息相关的。
# Display surface screen = pygame.display.set_mode((width, height)) # Regular Surface second_surface = pygame.Surface((100, 200)) second_surface.fill((0, 255, 0)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: ...
接下来,我们需要设置字体和字体大小,并创建一个渲染文本的Surface对象 BLACK = (0, 0, 0)WHITE = (255, 255, 255)FONT_SIZE = 64FONT = pygame.font.SysFont(None, FONT_SIZE)text = FONT.render(str(remain_time), True, color)text_rect = text.get_rect(center=(WIDTH // 2, HEIGHT // 2)...
pygame.Surface.subsurface - 创建一个引用其父级的新表面 pygame.Surface.get_parent - 找到地下的父母 pygame.Surface.get_offset - 在父母中找到子地下的位置 pygame.Surface.get_size - 获取Surface的尺寸 pygame.Surface.get_width - 获取Surface的宽度 ...
pygame.surface.get_abs_parent — 找到一个地下的顶级父 pygame.surface.get_offset — 发现在父母的孩子地下的位置 pygame.surface.get_abs_offset — 发现在其最高水平的孩子地下的绝对位置 pygame.surface.get_size — 得到表面的尺寸 pygame.surface.get_width — 得到表面的宽度 ...
transform.flip(img, False, True) else: return img return mirrored_img # 剪切变换 def shear(img, shear_x, shear_y): width, height = img.get_size() sheared_img = pygame.Surface((width + abs(shear_x * height), height + abs(shear_y * width))) sheared_img.set_colorkey((0, 0, ...