Class WorldTextComponent
- Namespace
- Stride.CommunityToolkit.Rendering.Text
- Assembly
- Stride.CommunityToolkit.dll
Draws text that lives in the scene: positioned by the entity's transform, scaled by perspective, and occluded by geometry standing in front of it.
[DefaultEntityComponentProcessor(typeof(WorldTextProcessor), ExecutionMode = ExecutionMode.Runtime)]
[AllowMultipleComponents]
[DataContract("WorldTextComponent")]
[Display("World Text (call AddWorldTextRenderer)", null, Expand = ExpandRule.Once)]
[ComponentCategory("Text")]
public class WorldTextComponent : EntityComponent, IIdentifiable
- Inheritance
-
WorldTextComponent
- Implements
- Inherited Members
Remarks
This is the counterpart to EntityTextComponent, which is screen-space: that one projects an anchor point and draws flat pixels on top of everything, while this one draws the text as part of the world. Use that one for HUDs and labels that must always be readable, and this one when the text should look like it belongs in the scene.
Add WorldTextRenderer to the graphics compositor for anything to appear.
entity.Add(new WorldTextComponent
{
Text = "Spawn",
Height = 0.4f,
Anchor = TextAnchor.BottomCenter,
Billboard = true
});
Constructors
WorldTextComponent()
Initializes a new instance of the WorldTextComponent class.
public WorldTextComponent()
Properties
Alignment
Gets or sets how the lines of a multi-line text sit relative to one another.
public TextAlignment Alignment { get; set; }
Property Value
Anchor
Gets or sets which point of the text sits on the entity's position. Defaults to MiddleCenter.
public TextAnchor Anchor { get; set; }
Property Value
Remarks
Centred by default, unlike the screen-space component: world text is usually placed at a thing rather than hung off the corner of one.
AutoScale
Gets or sets whether the rasterisation size follows the display's scale, so text on a 150% display is drawn from glyphs 1.5x the size and stays as sharp as it is on a 100% monitor. Defaults to true.
public bool AutoScale { get; set; }
Property Value
Remarks
Sharpness only: the text is Height tall in the world whatever the display, so
nothing moves or resizes. The factor comes from DisplayScale, shared with everything else
in the toolkit that follows the display, and only applies when the process is DPI aware.
GlowSize is in font pixels and scales along, so the glow keeps its reach.
Billboard
Gets or sets whether the text turns to face the camera. Defaults to true.
public bool Billboard { get; set; }
Property Value
Remarks
When false the text keeps the entity's own orientation, so it can be laid flat on a floor or fixed to a wall and will foreshorten and disappear edge-on like any other surface.
DepthTest
Gets or sets whether scene geometry in front of the text hides it. Defaults to true.
public bool DepthTest { get; set; }
Property Value
Remarks
This is the whole point of world text as opposed to the screen-space kind. Turning it off makes the text draw over everything while still being positioned and scaled in the world.
FadeStartDistance
Gets or sets the distance from the camera at which the text starts fading out, in world units.
public float? FadeStartDistance { get; set; }
Property Value
Font
Gets or sets the font. Leave null to use Stride's default font.
public SpriteFont? Font { get; set; }
Property Value
FontSize
Gets or sets the size the glyphs are rasterised at, in pixels. Defaults to 32.
public float FontSize { get; set; }
Property Value
Remarks
This is sharpness, not size on screen - Height decides how big the text is in the world. Raise it when text is viewed close up and looks soft; it costs glyph cache space. On a scaled display the glyphs are rasterised that much larger while AutoScale is on, because the same world height covers that many more pixels there.
GlowColor
Gets or sets the colour of a soft glow drawn behind the letters. Leave it fully transparent - an alpha of zero, the default - for no glow. Its alpha is the glow's strength.
public Color GlowColor { get; set; }
Property Value
Remarks
A HUD or a neon sign: light text on a glow of a deeper hue reads as lit rather than painted. The glow is the text itself drawn again in this colour, offset in a ring around the letters, so it scales with the text and follows every glyph exactly.
GlowSize
Gets or sets how far the glow reaches from the letters, in font pixels at FontSize. Defaults to 0. A tenth of the font size is a crisp halo; a quarter is a bloom.
public float GlowSize { get; set; }
Property Value
Height
Gets or sets the height of the text in world units. Defaults to 1.
public float Height { get; set; }
Property Value
Remarks
The text is scaled so the whole block - every line of it - is this tall, then scaled again by the entity's transform. Expressing it this way means changing FontSize for sharpness does not also change how big the text appears.
IsVisible
Gets or sets whether the text is drawn at all. Defaults to true.
public bool IsVisible { get; set; }
Property Value
KeepUpright
Gets or sets whether the text stays upright when billboarding. Defaults to true.
public bool KeepUpright { get; set; }
Property Value
Remarks
Upright text turns about the world Y axis only, so it never rolls when the camera tilts - which is what a label standing in a scene should do. Set to false to face the camera squarely from any angle, including from directly above.
MaxDistance
Gets or sets the distance beyond which the text is not drawn, in world units.
public float? MaxDistance { get; set; }
Property Value
Offset
Gets or sets a local-space offset applied before the entity's rotation.
public Vector3 Offset { get; set; }
Property Value
Opacity
Gets or sets an overall opacity from 0 to 1. Defaults to 1.
public float Opacity { get; set; }
Property Value
Remarks
A dimmer over everything the component draws: the letters, at TextColor's own alpha, and the GlowColor behind them. Distance fading drives this same dimmer.
Text
Gets or sets the text to draw.
public required string Text { get; set; }
Property Value
TextColor
Gets or sets the text colour. Defaults to White.
public Color TextColor { get; set; }