Thursday, April 12, 2007

GameComponent of BuddhaCpp

BuddhaCpp got to provide GameComponent class group, but that is not compoleted, yet. Main classes are only GameComponent class and DrawableComponent class. Interfaces of them still don't have been defined.

How to define your sub-class?

class MyClass : public GameComponent
{
public:
  MyClass(Game* game);
  void Update(GameTime gameTime);
};

For changing update-order, you may call SetUpdateOrder(). Now you have to call this in the constructor.

MyClass::MyClass(Game* game)
  : GameComponent(game)
{
  SetUpdateOrder(20);
}

After you create an instance, you adds it to ComponentCollection of your Game instance.

MyClass* myComp = new MyClass(this);
GetComponents()->Add(myComp);

The case of DrawableComponent is the following;

class MyClass : public DrawableComponent
{
public:
  MyClass(Game* game);
  void Update(GameTime gameTime);
  void Draw(GameTime gameTime);
};

For chaning draw-order, uses SetDrawOrder().

No comments: