Jump to content

Inheritance and Entity objects


martyj
 Share

Recommended Posts

I was wondering how we could use inheritance with the Entity class to allow code re-use

 

For example, I have an animaited model, (a Knight)

I have another animated model, (a Bat)

 

I want the Knight and Bat to have a few functions to start animations, a generic drawing, ect.

 

I want the Knight and Bat to also have seperate functions as well such as the Bat will Fly(), where as the Knight will Walk().

 

How could I tie a leadwerks Entity with a custom overloaded class to handle the comonalities of these two objects, but also allow for the unique functions for their class.

 

I should mention I'd like to be abe to add these Entities with the GUI editor.

 

Basically in C++ I want to have something like this:

 

 

class AnimatedModel : Entity

{

public:

void StartAnimation(Sequence, Duration, Loop, DistanceBased);

}

 

class Knight : AnimatedModel

{

public:

void Walk();

}

 

class Bat : AnimatedModel

{

public:

void Fly();

}

 

Using ToLua++ these could be callable in Lua.

Link to comment
Share on other sites

My preference is usually composition.

 

class Knight
{
private:
  Entity* model;
  Animations* animations;
};

 

I would examine if I need functions like Walk() and Fly(). They are basically just MoveTo() functions. Each type would just determine what animation to play when it moves

  • Upvote 1
Link to comment
Share on other sites

Ok, I see one problem fixed. Using Hooks you can recieve the in game-events from the engine.

 

How do I take an entity in LE3's map and easily tie it to a class?

 

The only thing I can think of is creating a ToLua++ function to register an object to a native class.

 

Can anyone thing of a better way?

 

Thanks for the input everyone.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...