Class ShapeComponent
Draws a flat shape at this entity's world transform through a ShapeBatch, so shapes
take part in Stride's component system - scripts, hierarchy, enable and disable - without needing
a model or a material. Nothing else is required: where the game called AddShapeBatch() the
shape draws through that batch, and otherwise through a depth-tested one the processor registers
for itself, which is also how the shape shows in Game Studio's scene editor.
[DefaultEntityComponentProcessor(typeof(ShapeProcessor), ExecutionMode = ExecutionMode.All)]
[DataContract("ShapeComponent")]
[Display("Shape", null, Expand = ExpandRule.Once)]
[ComponentCategory("Rendering")]
public sealed class ShapeComponent : ActivableEntityComponent, IIdentifiable
- Inheritance
-
ShapeComponent
- Implements
- Inherited Members
Remarks
The entity's world matrix places the shape: its X and Y axes become the plane the shape lies in, so a rotated entity carries the shape into 3D, and the length of the X axis is taken as a uniform scale. In a 2D scene, where entities only ever rotate about Z, this is just position and rotation.
Shapes submitted this way draw before manual ShapeBatch calls made later in the same frame.
Fields
Inherit
Assigned to BorderWidth, FillAlpha or GlowWidth to take the batch's value instead of one set here.
public static readonly float Inherit
Field Value
Properties
Batch
The batch this shape draws through, or null to use the game's default - the first one
registered with AddShapeBatch().
[DataMemberIgnore]
public ShapeBatch? Batch { get; set; }
Property Value
Remarks
Set this when a scene has more than one batch: the default is whichever batch the game registered first, which may be depth-tested and hide the shape behind scene geometry. Not serialized; assign it from code.
Billboard
Whether the shape faces the camera instead of lying in the entity's own plane. The entity's rotation and scale are ignored when this is set; only its position is used.
public bool Billboard { get; set; }
Property Value
BorderWidth
Outline width in on-screen pixels for this shape, or Inherit to use the batch's BorderWidth.
public float BorderWidth { get; set; }
Property Value
Color
The outline colour; the fill derives from it unless FillColor is set.
public Color Color { get; set; }
Property Value
FillAlpha
Fill intensity for this shape, 0 to 1, or Inherit to use the batch's Alpha. Set 0 for an unfilled outline.
public float FillAlpha { get; set; }
Property Value
FillColor
The fill's own colour for this shape. Leave it fully transparent - an alpha of zero, which is the default - to use the batch's Color, which itself defaults to filling with the outline colour. For a see-through fill use FillAlpha rather than a transparent colour here.
public Color FillColor { get; set; }
Property Value
GlowColor
The glow's colour for this shape. Leave it fully transparent - an alpha of zero, which is the default - to use the batch's Color, which itself defaults to the outline colour.
public Color GlowColor { get; set; }
Property Value
GlowWidth
Width of a soft glow outside this shape's outline, in on-screen pixels, or Inherit to use the batch's Width. Set 0 for none.
public float GlowWidth { get; set; }
Property Value
Pickable
Whether the shape answers TryPick(Vector2, out ShapeHit, float): the hit's Tag is then this component, and its entity one step away. Off by default.
public bool Pickable { get; set; }
Property Value
Radius
Optional rounding radius added around the outline, in world units.
public float Radius { get; set; }
Property Value
Vertices
The shape outline in local space, counter-clockwise. May be swapped or edited at runtime; the next frame draws the new outline. A single vertex with Radius set draws a circle; two vertices with a radius draw a capsule.
public List<Vector2> Vertices { get; set; }
Property Value
Remarks
A list rather than an array on purpose: Game Studio's property grid can add to and remove from a list, and the asset serializer can load one of any length, whereas an array is shown read-only and loads only into an instance of exactly its size.
Methods
Box(Vector2)
The outline of a box of size centred on the origin, counter-clockwise from the bottom-left
corner: the four vertices a rectangular shape needs, so they are not written out by hand.
public static Vector2[] Box(Vector2 size)
Parameters
sizeVector2The box's width and height, in world units.