This translation is community contributed and may not be up to date. We only maintain the English version of the documentation. Read this manual in English
ラベル(Label) コンポーネント(component)は、ゲーム空間内のテキストを画面に描画します。デフォルトでは、すべてのスプライト(sprite)およびタイルグラフィックスと一緒に並べ替えられ、描画されます。このコンポーネントには、テキストの描画方法を制御する一連のプロパティがあります。Defold の GUI はテキストをサポートしていますが、GUI 要素をゲームワールド(game world)に配置するのは難しい場合があります。ラベルを使うと、この配置が容易になります。
ラベルコンポーネントを作成するには、ゲームオブジェクト(game object)を 右クリック し、Add Component ▸ Label を選択します。

(同じテンプレートから複数のラベルのインスタンスを作成したい場合は、代わりに新しいラベルコンポーネントファイルを作成することもできます。Assets ブラウザーでフォルダーを 右クリック して New... ▸ Label を選択し、そのファイルを任意のゲームオブジェクトにコンポーネントとして追加します)

Font プロパティに使用するフォントを設定し、Material プロパティには、必ずフォントの種類に合ったマテリアル(material)を設定します。

Id、Position、Rotation、Scale プロパティに加えて、次のコンポーネント固有のプロパティがあります。
デフォルトのマテリアルでは、パフォーマンス上の理由から影の描画が無効になっていることに注意してください。
Blend Mode プロパティは、コンポーネント(component)のグラフィックスを、その背後のグラフィックスとどのようにブレンドするかを定義します。使用できるブレンドモード(blend mode)とその計算方法は次のとおりです:
src.a * src.rgb + (1 - src.a) * dst.rgbsrc.rgb + dst.rgbsrc.rgb * dst.rgbsrc.rgb - dst.rgb * dst.rgbPivot プロパティを設定すると、テキストの揃え方を変更できます。
Center、North、South に設定されている場合、テキストは中央揃えになります。West 系のいずれかのモードに設定されている場合、テキストは左揃えになります。East 系のいずれかのモードに設定されている場合、テキストは右揃えになります。
ラベルのテキストや、その他のさまざまなプロパティを取得、設定して、実行時にラベルを操作できます。
colorvector4)。outlinevector4)。shadowvector4)。scalenumber、各軸に沿って個別に拡大縮小する場合は vector3 を使います。sizevector3)。function init(self)
-- Set the text of the "my_label" component in the same game object
-- as this script.
label.set_text("#my_label", "New text")
end
function init(self)
-- Set the color of the "my_label" component in the same game object
-- as this script. Color is a RGBA value stored in a vector4.
local grey = vmath.vector4(0.5, 0.5, 0.5, 1.0)
go.set("#my_label", "color", grey)
-- ...and remove the outline, by setting its alpha to 0...
go.set("#my_label", "outline.w", 0)
-- ...and scale it x2 along x axis.
local scale_x = go.get("#my_label", "scale.x")
go.set("#my_label", "scale.x", scale_x * 2)
end
game.project ファイルには、ラベルに関するいくつかの プロジェクト設定 があります。