pygame设置text和image共同显示

时间:2023-03-08 18:59:03
pygame设置text和image共同显示
下面介绍一下如何用pygame将text文本和图片一起绑定到视图
部分重点用不同颜色做了标记,希望对大家有帮助

代码块:

%%writefile tranformtouxiang2.py
import pygame 
from pygame.locals import *
import sys
#初始化PyGame
pygame.init()
# 创建视窗
screen=pygame.display.set_mode((800,600))
# 加载图片(最好在while循环外加载,要不然会影响帧率性能)
fontImg=pygame.image.load('./img/fontImglmm1.png')
fontImg2=pygame.image.load('./img/fontImg6.png')
fontImg3=pygame.image.load('./img/fontImgLMR.png')
fontImg4=pygame.image.load('./img/wuzhe.png')
# 文本输入方法
font=pygame.font.Font('./font/meng.ttf',60)
text='Live up to youth @'
text3='Live up to oneself!'
text2='蓝天And白云'
textCon=font.render(text,True,[200,68,49])
textCon2=font.render(text2,True,[160,168,246])
textCon3=font.render(text3,True,[160,68,246])
while True:
    for event in pygame.event.get():
        if event.type==QUIT:
            sys.exit()
    # rotozoom旋转和放大综合函数
    a=pygame.transform.rotozoom(fontImg,66,1)
    a2=pygame.transform.rotozoom(fontImg2,22,0.6)
    a3=pygame.transform.rotozoom(fontImg3,78,0.6)
    a4=pygame.transform.scale(fontImg4,[360,360])
    # 窗口颜色
    screen.fill([255,255,255])
    # 多个视图绑定到视窗
    screen.blits([[a,[110,200]],[a2,[150,250]],[a3,[500,300]],[a4,[130,68]],[textCon,[50,400]],[textCon3,[250,480]],[textCon2,[100,50]]])
    pygame.display.update()