สร้างเกมด้วย Pygame Zero : image display and character display

สร้างไฟล์ draw_image2.py

# Pygame Zero Basic 
# สร้างเกมง่ายๆด้วย Pygame Zero By  wutdev
 
import pgzrun
 
#กำหนดขนาดหน้าต่าง
WIDTH = 500
HEIGHT = 500
 
#กำหนด sprite "red"
player = Actor("red") #รูป sprite "red.png" อยู่ที่ตำแหน่ง center=0,0 (รูปจะเก็บไว้ในโฟลเดอร์ images เสมอ)
player.pos = 0, 0  #กำหนดตำแหน่งของ sprite 0,0 อยู่มุมซ้ายบน ตามตำแหน่งพิกัดของ pygame zero
 
#เริ่มวาดภาพ
def draw():
   #screen.draw.text("draw.text", (0, 0)) # รูปแบบการใช้งาน  screen.draw.text("ข้อความ", (x, y) )
    
    #ระบุสีและขนาดตัวอักษร
    mycolor = "red"  #สีตัวหนังสือสีแดง 
    screen.draw.text("Hello! Pygame Zero", (100, 220), color=mycolor, fontsize=48)
    #แสดงข้อความตัวอักษร "Hello! Pygame Zero" ที่ตำแหน่ง100,200 สี และขนาดฟ้อนต์ 48
 
#รันโปรแกรม
pgzrun.go()

ทดลอง run จะได้ตามรูป

จะได้ข้อความ สีแดง “Hello! Pygame Zero” อยู่กลางจอ