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()

转载于:https://www.cnblogs.com/Dark-fire-liehuo/p/9724232.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值