To demonstrate the registration process, we will create a simple actor that will display a rotating model, and register it to the game.
First, define the class for the actor, inheriting from Actor
#include <actor/Actor.h>
#include <graphics/AnimModel.h>
class DemoActor : public Actor {
public:
static Profile* sProfile;
DemoActor(const ActorCreateParam& param);
~DemoActor() override = default;
Result create() override;
bool execute() override;
bool draw() override;
private:
AnimModel* mModel;
};
To learn more about the actor lifecycle, see Actor.
Next, register the actor to the game using the getRegistrar() function we created earlier:
Profile* DemoActor::sProfile = getRegistrar()->newProfile<DemoActor>("demo_actor")
.resources<"star_coin">(ProfileInfo::cResType_Course)
.build();
The builder has additional methods for setting different properties of the profile, see red::ProfileBuilder for more information.
Finally, create the actor's constructor and implement the lifecycle functions:
DemoActor::DemoActor(const ActorCreateParam& param)
: Actor(param)
, mModel(nullptr)
{ }
ActorBase::Result DemoActor::create() {
mModel = AnimModel::create("star_coin", "star_coinA");
return cResult_Success;
}
bool DemoActor::execute() {
mAngle.z() += sead::Mathf::deg2idx(2.0f);
mModel->update(mPos, mAngle, mScale);
return true;
}
bool DemoActor::draw() {
mModel->draw();
return true;
}
Finally, to test the actor, you must inform the level editor that it exists so that it can be placed in a level. See here for an example.