我正在尝试使用pygame在python中制作钢琴拼贴。所以,我开始制作一个介绍窗口,但我无法在进入窗口中上传背景图片1。我其实想要显示名字' Piano tiles'每当玩家开始游戏时都有背景图像。这是我的代码:
import pygame,os,random,time
from pygame.locals import *
wix=800
wiy=800
pygame.init()
white=(255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,155,0)
clock = pygame.time.Clock()
smallfont = pygame.font.SysFont("comicsansms", 25)
medfont = pygame.font.SysFont("comicsansms", 50)
largefont = pygame.font.SysFont("comicsansms", 100)
gameDisplay=pygame.display.set_mode((wix,wiy))
bg = pygame.image.load("background.jpg")
pygame.display.set_caption("Piano Tiles")
def game_intro():
screen=pygame.display.set_mode((wix,wiy))
intro =True
while intro:
bg = pygame.image.load("background.jpg")
screen.blit(bg,(0,0))
gameDisplay.fill(white)
message_to_screen("PIANO TILES",black,-100,"large")
pygame.display.update()
clock.tick(8)
def text_objects(text,color,size):
if size == "small":
textSurface = smallfont.render(text, True, color)
elif size == "medium":
textSurface = medfont.render(text, True, color)
elif size == "large":
textSurface = largefont.render(text, True, color)
return textSurface, textSurface.get_rect()
def message_to_screen(msg,color, y_displace=0, size = "small"):
textSurf, textRect = text_objects(msg,color, size)
textRect.center = (wix/ 2), (wiy / 2)+y_displace
gameDisplay.blit(textSurf, textRect)
game_intro()
pygame.time.wait(4000)
pygame.quit()
quit()
答案 0 :(得分:0)
您必须在stdin
之前使用fill(white)
,因为它可以清除屏幕。
看起来像这样
blit