pygame002

1 屏幕介紹

screen

2 要求

requ

3 pygame 的 代碼

game

4 屏幕尺寸設(shè)置

pygame.display.set_mode(r=(0,0),flags=0)
mode
import pygame,sys
size = width,height = 600,400
BLACK = 0,0,0
screen = pygame.display.set_mode(size,pygame.RESIZABLE)
speed = [1,1]
pygame.display.set_caption(" this game ")
ball = pygame.image.load("PYG02-ball.gif")
ball_rect = ball.get_rect()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    ball_rect = ball_rect.move(speed[0],speed[1])
    if ball_rect.left<0 or ball_rect.right>width:
        speed[0] = - speed[0]
    if ball_rect.top<0 or ball_rect.bottom>height:
        speed[1]=-speed[1]

    screen.fill(BLACK)
    screen.blit(ball,ball_rect)
    pygame.display.update()


image.png
  • 無邊框的設(shè)置
screen = pygame.display.set_mode(size,pygame.NOFRAME) #設(shè)置屏幕可調(diào)
screen = pygame.display.set_mode(size,pygame.FULLSCREEN) #設(shè)置屏幕全屏
無邊框
  • 窗口 設(shè)置
video
#需要判斷事件是 屏幕尺寸改變的事件 重新復(fù)制給屏幕 即可調(diào)節(jié)屏幕了 

elif event.type==pygame.VIDEORESIZE:
    size = width,height = event.size[0],event.size[1]
    screen = pygame.display.set_mode(size,pygame.RESIZABLE)

re
  • info 信息
info
前后對(duì)比

全屏需要設(shè)置 :

  • 設(shè)置屏幕的尺寸感知
vinfo = pygame.display.Info()
size = width,height = vinfo.current_w,vinfo.current_h 
  • 將上面的感知設(shè)置在set_mode 之前
screen = pygame.display.set_mode(size,pygame.FULLSCREEN)

5 標(biāo)題與圖標(biāo)設(shè)置

caption

使用 圖片:
https://python123.io/PY15/PYG03-flower.png

icon = pygame.display.image('flower.png')
pygame.display.set_icon(icon)

顯示圖標(biāo)

6 窗口感知

1

刷新函數(shù)


2

其中: flip 是 重新繪制整個(gè)窗口

update 是比較常用的 只是繪制部分有變化的部分 執(zhí)行速度更加快 ,如果場(chǎng)景變化不是很快 就使用 update

if pygame.display.get_active():
    ball_rect = ball_rect.move(1,1)

image.png

總結(jié)

2
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容