martyj Posted December 25, 2014 Share Posted December 25, 2014 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. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 25, 2014 Share Posted December 25, 2014 Not sure what the question is. You would have something like a Character base class that would have the entity Model, animation functions you mentioned, position, etc. The derived classes like the Knight and Bat would have functions for their unique characteristics. Quote Link to comment Share on other sites More sharing options...
martyj Posted December 25, 2014 Author Share Posted December 25, 2014 How can I reference custom classes in the GUI editor? I don't want code to initalize objects at positions. It would be better to use the GUI editor for object positioning. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 26, 2014 Share Posted December 26, 2014 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 1 Quote Link to comment Share on other sites More sharing options...
Roland Posted December 26, 2014 Share Posted December 26, 2014 Yes. Go with Ricks suggestion Quote AV MX Linux Link to comment Share on other sites More sharing options...
martyj Posted December 28, 2014 Author Share Posted December 28, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.