RichTextLabelのBBCode¶
はじめに¶
Label nodes are great for displaying basic text, but they have limits. If you want to change the color of the text, or its alignment, that change affects all of the text in the Label node. You can't have only one part of the text be one color, or only one part of the text be centered. To get around this limitation you would use a RichTextLabel.
RichTextLabel を使用すると、コントロールで複雑なテキストマークアップを表示できます。マークアップを生成するための組み込みAPIがありますが、BBCodeを解析することもできます。
BBCodeタグは、:ref:`XML source of the class reference <doc_updating_the_class_reference>`でもある程度使用することができます。
BBCodeを使用する¶
均一に書式設定されたテキストの場合は、"Text" プロパティで記述できますが、BBCodeマークアップを使用する場合は、代わりに "Bb Code" セクションの "Text" プロパティを使用する必要があります(bbcode_text
)。このプロパティに書き込むと、マークアップの解析がトリガーされ、要求に応じてテキストの書式が設定されます。この処理を行う前に、”Bb Code" セクションの "Enabled"チェックボックス(bbcode_enabled
)を切り替える必要があります。

たとえば、BBCode [color=blue]blue[/color]
は、単語 "blue" を青色でレンダリングします。

BBCodeの "Text" プロパティに書き込んだ後、通常の "Text" プロパティにBBCodeのないテキストが含まれていることに気付くとおもいます。テキストプロパティはBBCodeプロパティによって更新されるので、テキストプロパティを編集できないか、または編集するとBBCodeマークアップが失われます。テキストに対するすべての変更は、BBCodeパラメーターで行う必要があります。
注釈
For BBCode tags such as [b]
(bold), [i]
(italics) or [code]
to
work, you must set up custom fonts for the RichTextLabel node first.
There are no BBCode tags to control vertical centering of text yet.
リファレンス¶
Command |
タグ |
説明 |
太字 |
|
{text}を太字にします。 |
斜体 |
|
{text}を斜体にします。 |
下線 |
|
{text}に下線を付けます。 |
取り消し線 |
|
{text}に取り消し線を付けます。 |
コード |
|
Makes {text} use the code font (which is typically monospace). |
センター |
|
Makes {text} horizontally centered. |
右 |
|
Makes {text} horizontally right-aligned. |
フィル |
|
Makes {text} fill the RichTextLabel's width. |
インデント |
|
Increase the indentation level of {text}. |
** URL ** |
|
Show {url} as such, underline it and make it clickable. Must be handled with the "meta_clicked" signal to have an effect. See Handling [url] tag clicks. |
URL(名称) |
|
Makes {text} reference <url> (underlined and clickable). Must be handled with the "meta_clicked" signal to have an effect. See Handling [url] tag clicks. |
画像 |
|
リソース{path}の画像を挿入します。 |
サイズ変更された画像 |
|
(比率を保ちつつ)<width>を使用して、リソース{path}の画像を挿入します。 |
サイズ変更された画像 |
|
Insert image at resource {path} using <width>×<height>. |
フォント |
|
<path>のカスタムフォントを{text}に使用します。 |
色 |
|
Change {text} color; use name or # format, such as |
table |
|
Creates a table with <number> of columns. |
cell |
|
Adds cells with the {text} to the table. |
組み込みの色名¶
[color = <name>]タグで有効な色名のリスト:
aqua
black
blue
fuchsia
gray
green
lime
maroon
navy
purple
red
silver
teal
white
yellow
16進カラーコード¶
For opaque RGB colors, any valid 6-digit hexadecimal code is supported, e.g. [color=#ffffff]white[/color]
.
Short RGB color codes such as #6f2
(equivalent to #66ff22
) are also supported.
透過RGBカラーの場合、8桁の16進コードを使用できます。例 [color=#88ffffff]translucent white[/color]
。この場合、アルファチャネルはカラーコードの 最初の 値であり、最後の値ではないことに注意してください。
Handling [url]
tag clicks¶
By default, [url]
tags do nothing when clicked. This is to allow flexible use
of [url]
tags rather than limiting them to opening URLs in a web browser.
To handle clicked [url]
tags, connect the RichTextLabel node's
meta_clicked signal to a script function.
For example, the following method can be connected to meta_clicked
to open
clicked URLs using the user's default web browser:
# This assumes RichTextLabel's `meta_clicked` signal was connected to
# the function below using the signal connection dialog.
func _richtextlabel_on_meta_clicked(meta):
# `meta` is not guaranteed to be a String, so convert it to a String
# to avoid script errors at run-time.
OS.shell_open(str(meta))
For more advanced use cases, it's also possible to store JSON in an [url]
tag's option and parse it in the function that handles the meta_clicked
signal.
For example: [url={"example": "value"}]JSON[/url]
画像の垂直オフセット¶
画像を縦に揃えるには、画像にカスタムフォントを使用します。
``BitmapFont``リソースを作成する
ascent
プロパティに正の値を設定して、このビットマップフォントを設定します。これが高さオフセットですBBCodeタグを次のように設定します:
[font=<font-path>][img]{image-path}[/img][/font]
アニメーションエフェクト¶
BBCodeを使用して、さまざまなテキストアニメーションエフェクトを作成することもできます。カスタマイズ可能な5つのエフェクトがすぐに使用でき、独自のエフェクトも簡単に作成できます。
Wave(波)¶

Waveはテキストを上下に動かします。タグの形式は [wave amp=50 freq=2][/wave]
です。amp
は効果の高低を制御し、freq
はテキストの上下移動の速度を制御します。
Tornado(竜巻)¶

Tornaoは、テキストを円状に動かします。タグの形式は [tornado radius=5 freq=2][/tornado]
です。radius
はオフセットを制御する円の半径、freq
はテキストが円内を移動する速度です。
Shake(シェイク)¶

Shakeを指定するとテキストが揺れます。タグの形式は [shake rate=5 level=10][/shake]
です。rate
はテキストの揺れの速さを制御し、level
はテキストが原点からどれだけオフセットされるかを制御します。
Fade(フェード)¶

Fadeは、アニメーション化されていないテキストにフェード効果を作成します。タグの形式は [fade start=4 length=14][/fade]
です。start
は、フェードコマンドが挿入される場所に関連するフォールオフの開始位置を制御し、length
は、フェードアウトを行う文字数を制御します。
Rainbow(虹)¶

Rainbowは、時間とともに変化する虹色をテキストに与えます。タグ形式は [rainbow freq=0.2 sat=10 val=20][/rainbow]
です。freq
は1秒あたりの虹色が一周する数、sat
は虹の彩度、val
は虹の値です。