DEKI/ENGINE docs
manual api reference
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
Loading...
Searching...
No Matches

Keeps its object at a point on the screen, such as the top-left corner, on every screen size and while the camera moves. More...

#include <deki/ScreenAnchor.h>

Inherits Deki::Component.

Public Types

using Placer = void (*)(const Scene* scene, const ICamera& camera, int screenWidth, int screenHeight)
 Something else that places objects from the camera before each frame, such as a Tiled object layer with parallax.

Public Member Functions

 ScreenAnchor ()
 ~ScreenAnchor () override
Public Member Functions inherited from Deki::Component
 Component ()
 Component (const Component &)=delete
virtual ~Component ()=default
virtual void Awake ()
 Called once, after AssetRefs and ObjectRefs are resolved.
bool DeclaresUpdate () const
 True when this class (or a reflected base) declares Update(), as the codegen read it from the class declaration.
bool Deserialize (SceneFormat::SceneMsgPackParser &parser, uint32_t mapSize)
 Reads this component's fields from the MessagePack map the parser is at (mapSize key-value pairs), through the codegen's hash-switch deserializer.
ComponentType GetBaseType () const
 The direct component base's type id, so GetComponent<Base>() finds subclasses.
Object * GetOwner () const
ComponentType GetType () const
 The class's type id (TypeId<T>()), 0 for an instance with no type info.
const ComponentTypeInfo * GetTypeInfo () const
 The class entry this instance runs through.
bool HasAwoken () const
bool HasRefsResolved () const
bool HasStarted () const
bool IsRemoved () const
 True once RemoveComponent() has been called and the component is waiting for the end of the lifecycle phase to be deleted.
virtual void LoadAssets ()
 Loads the assets this component needs (sprites, fonts, ...).
void MarkAwoken ()
void MarkRefsResolved ()
void MarkRemoved ()
void MarkStarted ()
virtual bool NeedsAssetLoading () const
 True when LoadAssets() should be called.
virtual bool NeedsRuntimeUpdate () const
 True when RuntimeUpdate() should be called each frame.
virtual void OnAssetRefResolved (const char *propertyName, void *asset, const char *guid)
 Called after LifecycleManager resolves the AssetRef field propertyName to asset, loaded from guid.
virtual void OnPropertyChanged (const char *propertyName)
 Called when the editor changes the field propertyName, after both Execute() and Undo() of ModifyComponentPropertyCommand.
Component & operator= (const Component &)=delete
void RemapObjectRefs (const std::unordered_map< uint32_t, uint32_t > &idRemap)
 Rewrites ObjectRef ids through idRemap (old id -> new id), after Instantiate() gave the copies new ids.
void ResetRefsResolved ()
void ResolveObjectRefs (Scene *scene)
 Points every ObjectRef field at its object in scene (ObjectRef.id -> ObjectRef.resolved).
virtual void RuntimeUpdate (float deltaTime)
 Engine-driven per-frame work (physics, animation, ...), separate from the script-facing Update(): it runs in every mode, including the editor in edit mode, on components whose NeedsRuntimeUpdate() is true.
void SetOwner (Object *owner)
void SetTypeInfo (const ComponentTypeInfo *info)
 Attaches the class entry.
virtual void Start ()
 Called once before the first Update, after every component's Awake has run.
virtual void UnloadAssets ()
 Drops this component's asset pointers before shutdown.
virtual void Update ()
 Called every frame, only on classes that declare it.

Static Public Member Functions

static bool AddPlacer (Placer placer)
 Adds a placer; one already added is not added twice.
static void PlaceAll (const Scene *scene, const ICamera &camera, int screenWidth, int screenHeight)
 Moves every anchored object of scene, and every persistent one, to its point on a screen screenWidth x screenHeight pixels seen through camera.
static void RemovePlacer (Placer placer)

Public Attributes

ScreenPoint anchor = ScreenPoint::TopLeft
float offsetX = 0.0f
float offsetY = 0.0f
AnchorUpdate update = AnchorUpdate::Always

Static Public Attributes

static constexpr int kMaxPlacers = 8

Additional Inherited Members

Protected Attributes inherited from Deki::Component
bool m_HasAwoken
bool m_HasStarted
Object * m_Owner
bool m_RefsResolved
bool m_Removed
const ComponentTypeInfo * m_TypeInfo

Detailed Description

Keeps its object at a point on the screen, such as the top-left corner, on every screen size and while the camera moves.

For a HUD: hearts at Top Left, a score at Top Right.

The object sits at the anchor plus the offset, in meters, with Y up. Its position in the Transform is set from these, so it is not edited there; rotation and scale still come from the Transform, and children follow the object as usual.

Placement runs once per frame, before drawing, from the scene's camera and the screen size (PlaceAll). The object then has a normal world position, so input and other scripts see it where it is drawn. With update set to Once, the game places it on its first frame only; the editor, outside play, places it every frame so the Play view shows the picked screen.

Member Typedef Documentation

◆ Placer

using Deki::ScreenAnchor::Placer = void (*)(const Scene* scene, const ICamera& camera, int screenWidth, int screenHeight)

Something else that places objects from the camera before each frame, such as a Tiled object layer with parallax.

PlaceAll calls it after the anchors, with the same arguments, wherever a frame is drawn: the game, the Play view and the editor's previews.

Constructor & Destructor Documentation

◆ ScreenAnchor()

Deki::ScreenAnchor::ScreenAnchor ( )

◆ ~ScreenAnchor()

Deki::ScreenAnchor::~ScreenAnchor ( )
override

Member Function Documentation

◆ AddPlacer()

bool Deki::ScreenAnchor::AddPlacer ( Placer placer)
static

Adds a placer; one already added is not added twice.

False when the list is full (kMaxPlacers). Remove it before the code it points at is unloaded.

◆ PlaceAll()

void Deki::ScreenAnchor::PlaceAll ( const Scene * scene,
const ICamera & camera,
int screenWidth,
int screenHeight )
static

Moves every anchored object of scene, and every persistent one, to its point on a screen screenWidth x screenHeight pixels seen through camera.

The render system calls it before each frame; the editor calls it for the screen the Play view shows.

◆ RemovePlacer()

void Deki::ScreenAnchor::RemovePlacer ( Placer placer)
static

Member Data Documentation

◆ anchor

ScreenPoint Deki::ScreenAnchor::anchor = ScreenPoint::TopLeft

◆ kMaxPlacers

int Deki::ScreenAnchor::kMaxPlacers = 8
staticconstexpr

◆ offsetX

float Deki::ScreenAnchor::offsetX = 0.0f

◆ offsetY

float Deki::ScreenAnchor::offsetY = 0.0f

◆ update

AnchorUpdate Deki::ScreenAnchor::update = AnchorUpdate::Always

The documentation for this class was generated from the following file: