全屏显示
display.Info() 返回一个info对象
通过info对象的current_h,current_w可以获取到宽与高(在设置游戏窗口前创建,current_h,current_w 指的是显示器的高与宽,在设置完游戏窗口之后创建 current_h,current_w指的是游戏窗口的高与宽)
info = pygame.display.Info()
screen_obj = pygame.display.set_mode((info.current_w,info.current_h),flags)
pygame.display.flip()
屏幕可调节设置
当用户调节屏幕尺寸的时候 会发生一个pygame.VIDEORESIZE 事件(窗口大小更改)
event对象有一个属性 event.size值是一个元组 记录窗口宽与高
display.get_active() 当窗口不最小化的时候回返回True,否则返回False
while 1:
for event in pygame.event.get():
if event.type == pygame.VIDEORESIZE:
print(event.size)
screen_obj = pygame.display.set_mode(event.size, flags)
screen_obj.fill([255, 255, 255])
pygame.display.flip()
显示图片
1.加载图片
image = pygame.image.load(图片路径(最好使用相对路径))
2.绘制图片
需要使用屏幕对象 来调用blit(图片对象,图片需要绘制的位置(坐标))
3.刷新屏幕
display.update()刷新屏幕
display.flip()重新绘制屏幕
补充:
图片对象有一个get_size()方法 可以获取图片的大小
图片的缩放和旋转
1. transform.scale(缩放对象,目标大小(700,700))-->新的对象
2. transform.rotozoom(缩放/旋转对象,旋转的角度(0-360),缩放比例)————>新的对象
bg = pygame.image.load('image/hundouluo.jpg')
bg_size=bg.get_size()
print(bg_size)
new_bg=pygame.transform.rotozoom(bg,0,2)
new_bg_size=new_bg.get_size()
print(new_bg_size)
screen_obj = pygame.display.set_mode(new_bg_size)
游戏声音
1. 加载游戏声音
mixer.music.load(声音文件的路径(推荐使用相对路径))
2. 播放声音
mixer.music.play()
3. 关闭声音
mixer.music.stop()
music = pygame.mixer.music.load('music/1撕夜.mp3')
pygame.mixer.music.play()
pygame.mixer.music.play()
pygame.display.flip()
time.sleep(10)
pygame.mixer.music.stop()