GluonEngine::Component Class Reference

Adds functionality to GameObjects, is the final level in the GameObject hierarchy. More...

#include <component.h>

Inheritance diagram for GluonEngine::Component:
GluonCore::GluonObject QObject GluonEngine::CameraControllerComponent GluonEngine::DiscRendererComponent GluonEngine::DiscSectionRendererComponent GluonEngine::KeyboardInputComponent GluonEngine::MouseInputComponent GluonEngine::QtScriptComponent GluonEngine::ScriptingComponent GluonEngine::SoundEmitterComponent GluonEngine::SoundListenerComponent GluonEngine::SphereCollisionComponent GluonEngine::SpriteRendererComponent GluonEngine::TextRendererComponent GluonEngine::TouchInputComponent

List of all members.

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)
GameObjectgameObject ()
void setGameObject (GameObject *newGameObject)
void sanitize ()
virtual QString stringFromProperty (const QString &propertyName, const QString &indentChars) const

Properties

QString description
bool enabled

Detailed Description

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.


Constructor & Destructor Documentation

Component::Component ( QObject parent = 0  ) 

Definition at line 33 of file component.cpp.

Component::Component ( const Component other,
QObject parent = 0 
)

Definition at line 39 of file component.cpp.

Component::~Component (  ) 

Definition at line 45 of file component.cpp.


Member Function Documentation

QString Component::category (  )  const [virtual]
virtual void GluonEngine::Component::cleanup (  )  [inline, virtual]
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.

Returns:
The description of the Component instance
See also:
setDescription
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.

Parameters:
timeLapse The number of milliseconds passed since the last update
See also:
Game::runGame, 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.

Returns:
True if the Component is enabled, false if not
See also:
setEnabled
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)

Returns:
A pointer to the GameObject instance this Component is attached to
See also:
setGameObject, GameObject

Definition at line 126 of file component.cpp.

virtual void GluonEngine::Component::initialize (  )  [inline, virtual]
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.

See also:
GDLHandler::parseGDL

Reimplemented from GluonCore::GluonObject.

Definition at line 79 of file component.cpp.

void Component::setDescription ( const QString &  newDescription  ) 

Set the description of the Component

Parameters:
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

Parameters:
newEnabled The new value for the parameter
See also:
enabled

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!

Parameters:
newGameObject The GameObject instance to move this Component onto
See also:
gameObject, GameObject

Definition at line 132 of file component.cpp.

virtual void GluonEngine::Component::start (  )  [inline, virtual]
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.

Parameters:
propertyName The name of the property you wish to get in GDL property string form
Parameters:
indentChars The characters used for indenting the string
Returns:
The GDL representation of the property

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.

Parameters:
elapsedMilliseconds The amount of time in milliseconds which has passed since the last update
See also:
Game::runGame, draw

Reimplemented in GluonEngine::KeyboardInputComponent, GluonEngine::MouseInputComponent, GluonEngine::TouchInputComponent, GluonEngine::QtScriptComponent, GluonEngine::SphereCollisionComponent, and GluonEngine::ScriptingComponent.

Definition at line 67 of file component.cpp.


Property Documentation

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.


The documentation for this class was generated from the following files:
Generated on Mon Dec 27 13:13:43 2010 for Gluon by  doxygen 1.6.3