#全屏显示
screen=pygame.display.set_mode((640,480),0,32)
screen=pygame.display.set_mode((640,480),FULLSCREEN,32)
#获得机器可以支持的显示模式
pygame.disp.list_modes()
#将f绑定给全屏切换
if event.type == KEYDOWN:if event.key == K_f:Fullscreen = not Fullscreenif Fullscreen:screen = pygame.display.set_mode((640, 480), FULLSCREEN, 32)else:screen = pygame.display.set_mode((640, 480), 0, 32)
可改变尺寸的显示:
pygame.display.set_mode((640,480),RESIZEABLE,32)
if event.type==VIDEORESIZE:SCREEN_SIZE=event.sizeimport pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen_size=(640,480)
screen=pygame.display.set_mode(screen_size,RESIZABLE,32)
image=pygame.image.load('images/fugu.png')
while True:event=pygame.event.wait()if event.type==QUIT:exit()if event.type==RESIZABLE:screen_size=event.sizescreen=pygame.display.set_mode(screen_size,RESIZABLE,32)pygame.display.set_caption("window resize to:"+str(event.size))screen_width,screen_height=screen_sizescreen.fill((0, 0, 0))
#这个是按照比例复制平移背景for y in range(0,screen_height,image.get_height()):for x in range(0,screen_width,image.get_width()):screen.blit(image,(x,y))pygame.display.update()
还可以将其复合起来
pygame.display.set_mode(size,RESIZEABLE|FULLSCREEN,32)
#一定要设置可以切换的按键,要不然满屏的背景,直接按快捷键切换到别的软件或者模式就出来了
#使用字体模块:
font=pygame.font.SYSFont("arial",16)
#一旦创建了一个font对象,就是用render方法来写字了
font.render('myText',True,(0,0,0),(255,,255,255))
#第一个参数写的是文字,第二是否使用抗锯齿,开启会比较平滑,第三个是字体的颜色,第四个是背景的颜色,不写会默认是透明的
import pygame
from pygame.locals import *from sys import exit
pygame.init()
screen_size=(640,480)
screen_width,screen_height=screen_size
screen=pygame.display.set_mode(screen_size,RESIZABLE,32)
image=pygame.image.load('images/fugu.png')
background=pygame.image.load('images/sushiplate.jpg')
font=pygame.font.SysFont('arial',16)
front=font.render('hahaha',True,(0,0,0))
front_x=front.get_width()
print(front_x)
front_y=front.get_height()
print(front_y)
x=0
y=(screen_height-front_y)/2
while True:event=pygame.event.wait()if event.type==QUIT:exit()if event.type==RESIZABLE:screen_size=event.sizescreen=pygame.display.set_mode(screen_size,RESIZABLE,32)pygame.display.set_caption("window resize to:"+str(event.size))screen_width,screen_height=screen_sizescreen.fill((0, 0, 0))for y in range(0,screen_height,background.get_height()):for x in range(0,screen_width,background.get_width()):screen.blit(background,(x,y))x-=100
#更改位置,都是变的,循环一次然后跳出,然后在循环,要让每次都满足条件if x<-front_x:x=screen_width-front_xscreen.blit(front,(x,y))pygame.display.update()