API CanvasPanel - shmellyorc/Box GitHub Wiki
CanvasPanel
Namespace: Box.Entities.Container
Description
A specialized Panel
that automatically follows the camera, ensuring its child entities remain visible as the view moves. The panel’s position is recalculated each frame based on the camera’s current position and an adjustable offset.
Constructor
public CanvasPanel(params Entity[] children)
Creates the panel and adds any provided child entities to it, ready for positioning relative to the camera.
Properties
Property | Description |
---|---|
Vect2 Offset |
The panel’s offset relative to the camera’s center. Adjusting this moves the panel within the view; setting it marks the panel dirty for repositioning. |
Methods
Method Signature | Description | Returns |
---|---|---|
protected override void Update() |
Called once per frame to recalculate the panel’s world position as (Camera.Position - Renderer.Center) + Offset , then invokes base.Update() to update child entities. |
void |
Examples
// Create a CanvasPanel that sticks to the top-left of the camera view
var hudPanel = new CanvasPanel(scoreDisplay, healthBar)
{
Offset = new Vect2(10, 10)
};
// Add to the main game screen
mainScreen.AddEntity(hudPanel);
// Inside the game loop, the CanvasPanel.Update() automatically repositions before drawing its children.