Adds functionality to GameObjects, is the final level in the GameObject hierarchy. More...
#include <component.h>
Public Member Functions | |
Q_INVOKABLE | Component (QObject *parent=0) |
Component (const Component &other, QObject *parent=0) | |
~Component () | |
virtual QString | category () const |
virtual QVariant | toVariant (GluonObject *wrapThis) |
virtual void | initialize () |
virtual void | start () |
virtual void | update (int elapsedMilliseconds) |
virtual void | draw (int timeLapse=0) |
virtual void | stop () |
virtual void | cleanup () |
QString | description () const |
void | setDescription (const QString &newDescription) |
bool | enabled () const |
void | setEnabled (bool newEnabled) |
GameObject * | gameObject () |
void | setGameObject (GameObject *newGameObject) |
void | sanitize () |
virtual QString | stringFromProperty (const QString &propertyName, const QString &indentChars) const |
Properties | |
QString | description |
bool | enabled |
Adds functionality to GameObjects, is the final level in the GameObject hierarchy.
Component is a class which defines the required functionality for implementing components for use with Gluon. A component is the place where the vast majority of logic found in GluonEngine games exist. The six most important functions for users are the virtual initialize(), start(), update(), draw(), stop() and cleanup() functions. This class is the final step in the GameObject hierarchy.
Since a component is attached to exactly one GameObject, the position in the world and anything else related to the GameObject can be found by accessing gameObject() (for example finding other Components and such)
Implementation checklist:
Definition at line 61 of file component.h.
Component::Component | ( | QObject * | parent = 0 |
) |
Definition at line 33 of file component.cpp.
Definition at line 39 of file component.cpp.
Component::~Component | ( | ) |
Definition at line 45 of file component.cpp.
QString Component::category | ( | ) | const [virtual] |
Return the category of the component. Meta-data used for filtering and sorting components
Reimplemented in GluonEngine::SoundEmitterComponent, GluonEngine::SoundListenerComponent, GluonEngine::CameraControllerComponent, GluonEngine::DiscRendererComponent, GluonEngine::DiscSectionRendererComponent, GluonEngine::SpriteRendererComponent, GluonEngine::TextRendererComponent, GluonEngine::KeyboardInputComponent, GluonEngine::MouseInputComponent, GluonEngine::TouchInputComponent, GluonEngine::QtScriptComponent, GluonEngine::SphereCollisionComponent, and GluonEngine::ScriptingComponent.
Definition at line 50 of file component.cpp.
virtual void GluonEngine::Component::cleanup | ( | ) | [inline, virtual] |
The cleanup function is called whenever an object is no longer needed. This happens mostly during scene changes.
Reimplemented in GluonEngine::SoundEmitterComponent, GluonEngine::CameraControllerComponent, GluonEngine::DiscRendererComponent, GluonEngine::DiscSectionRendererComponent, GluonEngine::SpriteRendererComponent, GluonEngine::TextRendererComponent, GluonEngine::QtScriptComponent, and GluonEngine::ScriptingComponent.
Definition at line 143 of file component.h.
QString GluonEngine::Component::description | ( | ) | const |
The description of the Component instance. An arbitrary value used to tell other members of the game development team what the Component is used for.
void Component::draw | ( | int | timeLapse = 0 |
) | [virtual] |
The draw function is run every time the engine requests a redraw of the screen. Avoid putting any game logic in this function. The optional timeLapse depends on gameloop being used. By default Gluon uses a gameloop which runs update a fixed number of times per second, while draw is called as often as it can be. The timeLapse parameter then tells you how many milliseconds have passed since the last time update was run. This allows you to extrapolate draw positions of items and thus create a potentially smoother gaming experience.
timeLapse | The number of milliseconds passed since the last update
|
Reimplemented in GluonEngine::SoundEmitterComponent, GluonEngine::SoundListenerComponent, GluonEngine::CameraControllerComponent, GluonEngine::DiscRendererComponent, GluonEngine::DiscSectionRendererComponent, GluonEngine::SpriteRendererComponent, GluonEngine::TextRendererComponent, GluonEngine::QtScriptComponent, and GluonEngine::ScriptingComponent.
Definition at line 73 of file component.cpp.
bool GluonEngine::Component::enabled | ( | ) | const |
Whether or not the Component is enabled for use by the GameObject it is contained within.
GameObject * Component::gameObject | ( | ) |
Returns a pointer to the GameObject instance this instance of the Component is attached to. Use this for example to get the position or rotation relevant to the Component, or any other functionality found on GameObject (such as finding other Components)
Definition at line 126 of file component.cpp.
virtual void GluonEngine::Component::initialize | ( | ) | [inline, virtual] |
The initialize function is called whenever an initialized object is needed. This includes scene changes.
Reimplemented in GluonEngine::SoundEmitterComponent, GluonEngine::CameraControllerComponent, GluonEngine::DiscRendererComponent, GluonEngine::DiscSectionRendererComponent, GluonEngine::SpriteRendererComponent, GluonEngine::TextRendererComponent, GluonEngine::KeyboardInputComponent, GluonEngine::MouseInputComponent, GluonEngine::TouchInputComponent, GluonEngine::QtScriptComponent, and GluonEngine::ScriptingComponent.
Definition at line 99 of file component.h.
void Component::sanitize | ( | ) | [virtual] |
Function used on instantiation to fix the parent/child relationship. Used specifically by GDLHandler in the parseGDL() function. If you do not work on GDLHandler, it is unlikely you will need this function.
Reimplemented from GluonCore::GluonObject.
Definition at line 79 of file component.cpp.
void Component::setDescription | ( | const QString & | newDescription | ) |
Set the description of the Component
newDescription | The new description |
Definition at line 102 of file component.cpp.
void Component::setEnabled | ( | bool | newEnabled | ) |
Set the enabled parameter of the Component instance
newEnabled | The new value for the parameter
|
Definition at line 114 of file component.cpp.
void Component::setGameObject | ( | GameObject * | newGameObject | ) |
Move this Component to another GameObject. Please note that this will remove the Component from its current GameObject!
newGameObject | The GameObject instance to move this Component onto
|
Definition at line 132 of file component.cpp.
virtual void GluonEngine::Component::start | ( | ) | [inline, virtual] |
The start function is run once after each scene change, immediately before the first update
Reimplemented in GluonEngine::SoundEmitterComponent, GluonEngine::SoundListenerComponent, GluonEngine::CameraControllerComponent, GluonEngine::DiscRendererComponent, GluonEngine::DiscSectionRendererComponent, GluonEngine::SpriteRendererComponent, GluonEngine::TextRendererComponent, GluonEngine::KeyboardInputComponent, GluonEngine::MouseInputComponent, GluonEngine::TouchInputComponent, GluonEngine::QtScriptComponent, GluonEngine::SphereCollisionComponent, and GluonEngine::ScriptingComponent.
Definition at line 105 of file component.h.
virtual void GluonEngine::Component::stop | ( | ) | [inline, virtual] |
The stop function is run once when the gameloop is stopped. Use it for removing temporary data between runs. Reimplement this function if you have something that needs cleaning up between runs.
Reimplemented in GluonEngine::SoundEmitterComponent, GluonEngine::KeyboardInputComponent, GluonEngine::MouseInputComponent, GluonEngine::TouchInputComponent, GluonEngine::QtScriptComponent, GluonEngine::SphereCollisionComponent, and GluonEngine::ScriptingComponent.
Definition at line 137 of file component.h.
QString Component::stringFromProperty | ( | const QString & | propertyName, | |
const QString & | indentChars | |||
) | const [virtual] |
Adapted function which special cases access to properties with the type GluonEngine::Asset* - used by GDLHandler.
propertyName | The name of the property you wish to get in GDL property string form
|
Reimplemented from GluonCore::GluonObject.
Definition at line 138 of file component.cpp.
virtual QVariant GluonEngine::Component::toVariant | ( | GluonObject * | wrapThis | ) | [virtual] |
If you wish to be able to use your objects as properties, make sure to implement this function to return a QVariant which is of the type of your class.
void Component::update | ( | int | elapsedMilliseconds | ) | [virtual] |
The update function is run each time the game logic needs to be updated. Implement this function in inherited classed to allow for updates along with the rest of the GameObject hierarchy. Note that this is only for updating the game logic - any drawing functionality should be put into the draw function.
elapsedMilliseconds | The amount of time in milliseconds which has passed since the last update
|
Reimplemented in GluonEngine::KeyboardInputComponent, GluonEngine::MouseInputComponent, GluonEngine::TouchInputComponent, GluonEngine::QtScriptComponent, GluonEngine::SphereCollisionComponent, and GluonEngine::ScriptingComponent.
Definition at line 67 of file component.cpp.
QString Component::description [read, write] |
The description of the Component instance. An arbitrary value used to tell other members of the game development team what the Component is used for.
Definition at line 69 of file component.h.
bool Component::enabled [read, write] |
Whether or not the Component is enabled for use by the GameObject it is contained within.
Definition at line 74 of file component.h.