Pygame Zero演習2(画像表示と文字表示)

Python

Pygame Zeroで画像ファイルの表示と文字表示についてのサンプルです。

draw_image2.py

# Pygame Zeroで画像を表示2

# キャラクタ座標を別の指定方法で設定

import pgzrun

# 画面サイズ
WIDTH = 500
HEIGHT = 500

# キャラクタを生成
player_name = "kero"  # 拡張子を除いたファイル名 imagesフォルダ参照
player = Actor(player_name)
# キャラクタの座標を設定
player.pos = 0, 0  # player.topleft = 0, 0 とするとどうなるだろうか?

# 描画処理
def draw():
	screen.fill((128, 128,128))  # グレーで塗りつぶし
	player.draw()  # プレイヤーを画面に表示

# ゲームスタート
pgzrun.go()

draw_text.py

# Pygame Zeroで文字を描画

import pgzrun

# 画面サイズ
WIDTH = 500
HEIGHT = 500

# 描画処理
def draw():
	# 基本的な使い方 screen.draw.text("文字列", (x, y) )
	screen.draw.text("draw.text", (0, 0))

	# 色とフォントサイズを指定
	mycolor = 0, 0, 192  # 色
	screen.draw.text("Hello! Pygame Zero", (100, 220), color=mycolor, fontsize=48)

	# fontsフォルダに~.ttfのフォントがあればフォントの指定も可能
	#screen.draw.text("Hello! Pygame Zero", (100, 220), color=mycolor, fontsize=32, fontname="jackeyfont")
	

# ゲームスタート
pgzrun.go()

コメント