Pygame
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Pygame簡介
pygame
是一個Python的套件,主要用來創建 2D 遊戲和多媒體應用程式。它提供了一系列的功能,使開發者能夠輕鬆地處理圖形、音效、動畫以及使用者互動等方面。
建立開發環境
- 確定使否已安裝Python
- 開啟要建立環境的路徑
- 輸入下方指令建立一個新的環境
- 進入虛擬環境路徑並啟動
- 切換完成後輸入下面指令安裝套件
這樣就完成環境設定了
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
基本Pygame指令
基本範例程式碼
下面是官方提供的基本的範例程式碼,包括最基本的pygame需要的東西.後面會依序介紹他們的功能
初始化pygame物件
顯示視窗
- 設定顯示視窗物件(指定視窗的高度與寬度, flag是用來設定顯示模式的例如全螢幕等等)
- 設定視窗標題
- 顯示更新畫面(可以選擇是否只更新哪個區塊,如未設定則整個畫面更新)
- 獲取畫面資訊(解析度,顯示方式等)
- 切換螢幕顯示方式(全螢幕🔁視窗)
- 設定視窗的icon
設定畫布
Surface
是Pygame中一個非常重要的物件,它代表了所有可顯示的畫面、圖像或介面元素。幾乎所有在Pygame中的圖形繪製,都是在Surface
上進行的。
- 創建Surface
- 繪製圖形和顏色
- Surface圖像
- 複製Surface
- 旋轉Surface
- 透明度
- 繪製Surface到視窗中
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
前面說明完了最基本的語法,有了這些語法我們可以開始製作簡易的動畫了
基本動畫
基本控制事件(滑鼠鍵盤)
角色控制(Sprite)
簡易小遊戲