zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    原生拖动试验
    html+css创建提示框
    图片等比例缩放
    【css】多行文字图片混排容器内垂直居中解决方案
    网页中如何启用QQ交谈
    深入浅出Windows Phone 8应用开发
    ASP.NET MVC3 Dynamically added form fields model binding
    未来的学习计划(一)-概述
    有关对字符串的处理,需要用到List时的简化写法
    防火墙1433端口打开即可远程数据库
  • 原文地址:https://www.cnblogs.com/Dark-fire-liehuo/p/9724232.html
Copyright © 2011-2022 走看看