python的pygame游戏框架

版权声明:所有文章皆为李兴球先生原创,转载请注明出处,否则保留权利,追究责任。 https://blog.csdn.net/avskya/article/details/81301491

import pygame
from pygame.locals import *

def main():
    # 初始化屏幕
    pygame.init()
    screen = pygame.display.set_mode((480,360))
    pygame.display.set_caption('游戏世界欢迎你')

    # 填充背景
    background = pygame.Surface(screen.get_size())       #新建一个'面'对象,可以认为它是一张透明的纸      
    background = background.convert()
    background.fill((20, 20, 50))

    # 显示文本
    font = pygame.font.Font("C:/windows/fonts/msyh.ttf", 36)
    text = font.render("李兴球的pygame游戏世界欢迎你", 1, (10, 250, 250))
    textpos = text.get_rect()                           # textpos是一个矩形对象
    textpos.centerx = background.get_rect().centerx
    textpos.centery = background.get_rect().centery  
    
    background.blit(text, textpos)                      #把文本绘制到背景上

    # 绘制背景到屏幕上
    screen.blit(background, (0, 0))
    pygame.display.flip()

    # 事件循环
    while 1:
        for event in pygame.event.get():
            if event.type == QUIT:
                break

        screen.blit(background, (0, 0))
        pygame.display.flip()
    pygame.quit()


if __name__ == '__main__': main()
 

猜你喜欢

转载自blog.csdn.net/avskya/article/details/81301491