Difference between revisions of "love.graphics.printf (日本語)"

(Created page with "語句の折り返しと整列を行い、整形したテキストを描画します。 追加の注記は love.graphics.print を参照...")
 
(注釈: Imported/modfied the examples from Chinese page.)
Line 82: Line 82:
 
love.graphics.printf("This text is aligned center",100, 100, 200,"center") -- テキストを x = 200/2 + 100 = 200 の中央へ
 
love.graphics.printf("This text is aligned center",100, 100, 200,"center") -- テキストを x = 200/2 + 100 = 200 の中央へ
 
love.graphics.printf("This text is aligned right",100, 100, 200,"right") -- x = 100 + 200 = 300 へ右揃え
 
love.graphics.printf("This text is aligned right",100, 100, 200,"right") -- x = 100 + 200 = 300 へ右揃え
 +
</source>
 +
 +
日本語の表示方法(ファイルの文字コードはUTF-8です):
 +
<source lang="lua">
 +
function love.load()
 +
-- 日本語フォントの指定 (ここでは IPAexフォント(Ver.003.01) を使用しています: http://ipafont.ipa.go.jp/)
 +
        -- LOVE でフォントを使用する場合はフォントオブジェクトを作成するということに注意してください。
 +
font = love.graphics.newFont("ipaexm.ttf", 18) -- IPAex明朝(Ver.003.01)
 +
love.graphics.setFont(font)
 +
end
 +
 +
-- サンプルテキストは野口雨情(1882生~1945没)『大利根八十里を溯る』の関東の耶馬渓より引用。
 +
-- 作家別作品リスト:No.286 (青空文庫)
 +
-- http://www.aozora.gr.jp/index_pages/person286.html
 +
--
 +
function love.draw()
 +
love.graphics.printf("ここと銚子とは 五十里もあろに 水は寝ないで 流れてく", 100, 200)
 +
end
 +
 +
-- 参考:
 +
-- printf で禁則処理(日中韓)が正常に行われない不具合について (回避方法は禁則処理ルーチンを組むほかはありません)
 +
--
 +
-- Word wrap for CJK should not put punctuation at the front of a line
 +
-- https://bitbucket.org/rude/love/issues/1154/word-wrap-for-cjk-should-not-put
 
</source>
 
</source>
  

Revision as of 09:56, 3 May 2017

語句の折り返しと整列を行い、整形したテキストを描画します。

追加の注記は love.graphics.print を参照してください。

version 0.9.2 以前において、折り返しの実装は空白による語句の分割および、指定された制限範囲内に上手く合わさるのを確実にするために後方へ配置します。しかしながら、この方法では、この時点で実行終了してしまうが故に、語句間への空白の追加は完了して不足するので、画面へ表示されたときには、一部の行は与えられた制限を超過してしまい文字溢れを起こしてしまいます。この症状は version 0.10.0 以降では修正済です。

O.png 整列が予期したとおりに動作しないことがあります! 与えられた x/y 座標が、長方形の範囲で幅に制限されているときは、整列が行われなくなります。  


関数

概要

love.graphics.printf( text, x, y, limit, align )

引数

string text
テキスト文字列。
number x
x-軸の座標での位置。
number y
y-軸の座標での位置。
number limit
この水平ピクセルの後に行を折り返す長さ。
AlignMode align ("left")
テキストの揃え方。

返値

ありません。

関数

LÖVE 0.9.0 から使用可能
この異形は以前のバージョンでは非対応です。

概要

love.graphics.printf( text, x, y, limit, align, r, sx, sy, ox, oy, kx, ky )

引数

string text
テキスト文字列。
number x
x-軸の座標での位置。
number y
y-軸の座標での位置。
number limit
この水平ピクセルの後に行を折り返す長さ。
AlignMode align ("left")
テキストの揃え方。
number r (0)
方向 (弧度)。
number sx (1)
尺度変更係数 (x-軸)。
number sy (sx)
尺度変更係数 (y-軸)。
number ox (0)
原点の支距 (x-軸)。
number oy (0)
原点の支距 (y-軸)。
number kx (0)
剪断係数 (x-軸)。
number ky (0)
剪断係数 (y-軸)。

返値

ありません。

関数

LÖVE 0.10.0 から使用可能
この異形は以前のバージョンでは非対応です。

概要

love.graphics.printf( coloredtext, x, y, wraplimit, alignmode, angle, sx, sy, ox, oy, kx, ky )

引数

table coloredtext
色を有しているテーブルおよび {color1, string1, color2, string2, ...} 形式でオブジェクトへ追加する文字列。
table color1
次回の文字列で使用する色のテーブルとして赤色、緑色、青色、および選択制の透過成分を {red, green, blue, alpha} 形式にて有するテーブル。
string string1
以前の色により指定された色を有するテキスト文字列。
table color2
次回の文字列で使用する色のテーブルとして赤色、緑色、青色、および選択制の透過成分を {red, green, blue, alpha} 形式にて有するテーブル。
string string2
以前の色により指定された色を有するテキスト文字列。
tables and strings ...
追加の色と文字列。
number x
テキストの位置 (x-軸)。
number y
テキストの位置 (y-軸)。
number wraplimit
自動で次行への行送り処理を行うまでのピクセル単位によるテキストの最大幅。
AlignMode align
テキストの整列位置。
number angle (0)
方向 (弧度)。
number sx (1)
尺度変更係数 (x-軸)。
number sy (sx)
尺度変更係数 (y-軸)。
number ox (0)
原点の支距 (x-軸)。
number oy (0)
原点の支距 (y-軸)。
number kx (0)
剪断 / 斜行係数 (x-軸)。
number ky (0)
剪断 / 斜行係数 (y-軸)。

返値

ありません。

注釈

love.graphics.setColor により設定された色はテキストの色と混合 (乗算) されます。

用例

右揃えで水平方向への制限を 125 にしてテキストを画面へ描画します。

love.graphics.printf("This text is aligned right, and wraps when it gets too big.", 25, 25, 125, "right")

注釈

注意点として 引数 limit はテキストの'中'および左'揃えの位置に影響します。

love.graphics.printf("This text is aligned center",100, 100, 200,"center") -- テキストを x = 200/2 + 100 = 200 の中央へ
love.graphics.printf("This text is aligned right",100, 100, 200,"right") -- x = 100 + 200 = 300 へ右揃え

日本語の表示方法(ファイルの文字コードはUTF-8です):

function love.load()
	-- 日本語フォントの指定 (ここでは IPAexフォント(Ver.003.01) を使用しています: http://ipafont.ipa.go.jp/)
        -- LOVE でフォントを使用する場合はフォントオブジェクトを作成するということに注意してください。
	font = love.graphics.newFont("ipaexm.ttf", 18) -- IPAex明朝(Ver.003.01)
	love.graphics.setFont(font)
end

-- サンプルテキストは野口雨情(1882生~1945没)『大利根八十里を溯る』の関東の耶馬渓より引用。
-- 作家別作品リスト:No.286 (青空文庫)
-- http://www.aozora.gr.jp/index_pages/person286.html
--
function love.draw()
	love.graphics.printf("ここと銚子とは 五十里もあろに 水は寝ないで 流れてく", 100, 200)
end

-- 参考:
-- printf で禁則処理(日中韓)が正常に行われない不具合について (回避方法は禁則処理ルーチンを組むほかはありません)
--
-- Word wrap for CJK should not put punctuation at the front of a line
-- https://bitbucket.org/rude/love/issues/1154/word-wrap-for-cjk-should-not-put

関連



そのほかの言語