0

如何显示可调整大小窗口的文本?另外,不同的情况可以有不同的背景吗?例如,我希望“游戏欢迎”有一个背景图像,而主菜单有另一个。

import pygame
from pygame.locals import *
import numpy as np
import matplotlib.pyplot as plt
import argparse
import threading, os, sys, time

pygame.init()
pygame.display.set_caption("AI Battlehip Game")
FPS = pygame.time.Clock()

red_ = (255,0,0)

def background_image_settings(back_end_image):
    back_end_image_set = pygame.image.load(back_end_image)
    screen = pygame.display.set_mode((1200,700), HWSURFACE|DOUBLEBUF|RESIZABLE)
    screen.blit(pygame.transform.scale(back_end_image_set, (1200,700)), (0,0))
    pygame.display.flip()
    try:                                                    #This function is responsible for making the window resizable and creating the background (in my case it is picture)
        while True:
            pygame.event.pump()
            event = pygame.event.wait()
            if event.type == QUIT:
                pygame.display.quit()
            elif event.type == VIDEORESIZE:
                screen = pygame.display.set_mode(event.dict['size'], HWSURFACE|DOUBLEBUF|RESIZABLE)
                screen.blit(pygame.transform.scale(back_end_image_set,event.dict['size']), (0,0))
                pygame.display.flip()
    except:
        pass

def text_objects(text, font):
    textSurface = font.render(text, True, red_check)    #This function is responsible for making the text colourful and font.   #Have seen it working with TextSurf, TextRect = text_objects(text, largeText)
    return textSurface, textSurface.get_rect()        


background_image_settings(r'/Users/user1/Desktop/Project work/images/backgroundimage2.jpg')
4

1 回答 1

0

screen.blit()在某个公式乘以屏幕宽度和高度的位置:

例如,在高尔夫模拟器中,您可以使用如下代码:

window.blit(stroke_label, (SCREEN_WIDTH - (.21+.02*math.floor(math.log10(strokes))) * SCREEN_WIDTH, SCREEN_HEIGHT - .985 * SCREEN_HEIGHT))
于 2019-03-25T16:48:50.670 回答