Game Develop C++ Platform: RuntimeObject Class Reference

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RuntimeObject Class Reference
Game engine | Classes defining main concepts ( also found in Game engine )

A RuntimeObject is something displayed on the scene. More...

`#include <RuntimeObject.h>`

Inheritance diagram for RuntimeObject:
[legend]
Collaboration diagram for RuntimeObject:
[legend]

## Public Member Functions

| RuntimeObject (RuntimeScene &scene, const gd::Object &object)
| Construct a RuntimeObject from an object. More...
| RuntimeObject (const RuntimeObject &object)
| Copy constructor. Calls Init().
RuntimeObject & | operator= (const RuntimeObject &object)
| Assignment operator. Calls Init().
virtual | ~RuntimeObject ()
| Default destructor.
virtual RuntimeObject * | Clone () const
| Must return a pointer to a copy of the object. A such method is needed to do polymorphic copies. More...
virtual bool | ExtraInitializationFromInitialInstance (const gd::InitialInstance &position)
| Called by RuntimeScene when creating the RuntimeObject from an initial instance. More...
virtual bool | Draw (sf::RenderTarget &renderTarget)
| Draw the object. More...
const std::string & | GetName () const
| Get the name of the object.
const std::string & | GetType () const
| Get the type of the object.
int | GetZOrder () const
| Query the Z order of the object.
void | SetZOrder (int zOrder_)
| Change the Z order of the object.
bool | IsHidden () const
| Return if the object is hidden or not.
bool | IsVisible () const
| Return if the object is visible ( not hidden )
void | SetHidden (bool hide=true)
| Hide/Show the object.
void | SetLayer (const std::string &layer_)
| Change the layer of the object.
const std::string & | GetLayer () const
| Get the layer of the object.
bool | IsOnLayer (const std::string &layer_) const
| Check if the object is on a layer.
virtual std::vector< Polygon2d > | GetHitBoxes () const
| Get the object hitbox(es) More...
virtual void | UpdateTime (float timeElapsed)
| Called at each frame so as to update internal object's things using time ( Such as animation for a sprite ). More...
virtual float | GetWidth () const
| Get the width of the object.
virtual float | GetHeight () const
| Get the height of the object.
virtual void | SetWidth (float)
| Set the new width of the object. More...
virtual void | SetHeight (float)
| Set the new height of the object. More...
virtual bool | SetAngle (float)
| Get the angle of the object, in degrees. More...
virtual float | GetAngle () const
| Get the angle of the object, in degrees.
float | GetX () const
| Get the X coordinate of the object in the layout.
float | GetY () const
| Get the Y coordinate of the object in the layout.
void | SetX (float x_)
| Change X position of the object. More...
void | SetY (float y_)
| Change Y position of the object. More...
virtual void | OnPositionChanged ()
virtual float | GetDrawableX () const
| Get the real X position where is renderer the object. More...
virtual float | GetDrawableY () const
| Get the real Y position where is renderer the object. More...
virtual float | GetCenterX () const
| Get the X position of the center, relative to the position returned by GetDrawableX().
virtual float | GetCenterY () const
| Get the Y position of the center, relative to the position returned by GetDrawableY().
bool | ClearForce ()
| Delete all forces applied to the object.
Object's variables
Members functions providing access to the object's variables.
const gd::VariablesContainer & | GetVariables () const
| Provide access to the gd::VariablesContainer member containing the object variables.
gd::VariablesContainer & | GetVariables ()
| Provide access to the gd::VariablesContainer member containing the object variables.
Automatism related functions
Functions related to automatisms management.
void | DoAutomatismsPreEvents (RuntimeScene &scene)
| Call each automatism so that they do their work before events.
void | DoAutomatismsPostEvents (RuntimeScene &scene)
| Call each automatism so that they do their work after the events were runn.
gd::Automatism * | GetAutomatismRawPointer (const std::string &name)
gd::Automatism * | GetAutomatismRawPointer (const std::string &name) const
virtual bool | HasAutomatismNamed (const std::string &name) const
| Return true if the object has the automatism with the specified name.
Functions meant to be used by events generated code
void | DeleteFromScene (RuntimeScene &scene)
void | PutAroundAPosition (float positionX, float positionY, float distance, float angleInDegrees)
void | AddForce (float x, float y, float clearing)
void | AddForceUsingPolarCoordinates (float angle, float length, float clearing)
void | AddForceTowardPosition (float positionX, float positionY, float length, float clearing)
void | AddForceToMoveAround (float positionX, float positionY, float angularVelocity, float distance, float clearing)
void | AddForceTowardObject (RuntimeObject *object, float length, float clearing)
void | AddForceToMoveAroundObject (RuntimeObject *object, float velocity, float length, float clearing)
void | PutAroundObject (RuntimeObject *object, float length, float angleInDegrees)
void | SetXY (const char *xOperator, float xValue, const char *yOperator, float yValue)
void | Duplicate (RuntimeScene &scene, std::map< std::string, std::vector< RuntimeObject * > * > pickedObjectLists)
void | ActivateAutomatism (const std::string &automatismName, bool activate=true)
bool | AutomatismActivated (const std::string &automatismName)
bool | IsStopped ()
bool | TestAngleOfDisplacement (float angle, float tolerance)
double | GetSqDistanceWithObject (RuntimeObject *other)
double | GetDistanceWithObject (RuntimeObject *other)
double | GetVariableValue (const std::string &variable)
const std::string & | GetVariableString (const std::string &variable)
void | SeparateFromObjects (std::map< std::string, std::vector< RuntimeObject * > * > pickedObjectLists)
void | SeparateObjectsWithoutForces (std::map< std::string, std::vector< RuntimeObject * > * > pickedObjectLists)
void | SeparateObjectsWithForces (std::map< std::string, std::vector< RuntimeObject * > * > pickedObjectLists)

## Protected Member Functions

void | Init (const RuntimeObject &object)
| Initialize object using another object. Used by copy-ctor and assign-op. More...

## Protected Attributes

std::string | name
| The full name of the object.
std::string | type
| Which type is the object. ( To test if we can do something reserved to some objects with it )
float | X
| X position on the scene.
float | Y
| Y position on the scene.
int | zOrder
| Z order on the scene, to choose if an object is displayed before another object.
bool | hidden
| True to prevent the object from being rendered.
std::string | layer
| Name of the layer on which the object is.
std::map< std::string, gd::Automatism * > | automatisms
| Contains all automatisms of the object. Automatisms are the ownership of the object.
gd::VariablesContainer | objectVariables
| List of the variables of the object.
std::vector< Force > | forces
| Forces applied to the object.

## Forces

Members functions providing access to built-in force system used to move the objects
Force | force5
bool | UpdateForce (float ElapsedTime)
float | TotalForceX () const
float | TotalForceY () const
float | TotalForceAngle () const
float | TotalForceLength () const

## Detailed Description

A RuntimeObject is something displayed on the scene.

Games don't directly use this class: Extensions can provide object by deriving from this class, and redefining functions:

- An important function is RuntimeObject::Draw. It is called to render the object on the scene. This function take in parameter a reference to the target where render the object.
- RuntimeObject must be able to return their size, by redefining RuntimeObject::GetWidth and RuntimeObject::GetHeight
- RuntimeObject must be able to return the position where they have precisely drawn ( for example, Sprite can draw its image not exactly at the position of the object, if the origin point was moved ). It must also be able to return the position of their center. See RuntimeObject::GetDrawableX, RuntimeObject::GetDrawableY and RuntimeObject::GetCenterX, RuntimeObject::GetCenterY.
- If objects need to load resources ( for example textures at the loading ), it must be done inside the constructor creating the object from a gd::Object.
- When objects are placed at the start of the scene, scenes call RuntimeObject::ExtraInitializationFromInitialInstance, passing a gd::InitialInstance object in parameter ( containing information like the position where place the object ). Note that common information were already changed ( Position, angle, layer... ). You just need to setup the object with the information related to your object.
- Finally, objects can expose debugging features: RuntimeObject::GetPropertyForDebugger, RuntimeObject::ChangeProperty and RuntimeObject::GetNumberOfProperties

See also gd::Object which is used to store the initial objects before they are put on the scene.

See Also
  gd::Object

## Constructor & Destructor Documentation

RuntimeObject::RuntimeObject | ( | RuntimeScene & | scene,
|  | const gd::Object & | object
| ) |  |

Construct a RuntimeObject from an object.

The default implementation already takes care of setting common properties ( name, type, automatisms... ). Be sure to call the original constructor if you redefine it:

MyRuntimeObject(RuntimeScene & scene, const gd::Object & object) :
RuntimeObject(scene, object)
{
//...
}

Here is the call graph for this function:

## Member Function Documentation

void RuntimeObject::AddForceTowardPosition | ( | float | positionX,
|  | float | positionY,
|  | float | length,
|  | float | clearing
| ) |  |

Add a force toward a position

Here is the call graph for this function:

virtual RuntimeObject* RuntimeObject::Clone | ( | ) |  | const

inlinevirtual

Must return a pointer to a copy of the object. A such method is needed to do polymorphic copies.

Just redefine this method in your derived object class like this:

return new MyRuntimeObject(*this);

Reimplemented in RuntimeSpriteObject.

virtual bool RuntimeObject::Draw | ( | sf::RenderTarget & | renderTarget) |  |

inlinevirtual

Draw the object.

Parameters

  renderTarget | The SFML Rendertarget where object must be drawn.

Reimplemented in RuntimeSpriteObject.

virtual bool RuntimeObject::ExtraInitializationFromInitialInstance | ( | const gd::InitialInstance & | position) |  |

inlinevirtual

Called by RuntimeScene when creating the RuntimeObject from an initial instance.

Note
  The RuntimeScene already takes care of setting common properties ( Position, Angle... ) according to the InitialInstance. You only need to initialize extra properties specific to your object.

Reimplemented in RuntimeSpriteObject.

Automatism * RuntimeObject::GetAutomatismRawPointer | ( | const std::string & | name) |  |

Only used by GD events generated code

Automatism * RuntimeObject::GetAutomatismRawPointer | ( | const std::string & | name) |  | const

Only used by GD events generated code

virtual float RuntimeObject::GetDrawableX | ( | ) |  | const

inlinevirtual

Get the real X position where is renderer the object.

Most of the time, this will return the same value as GetX().
However, some objects may allow the origin point to be moved: In this case, you need to redefine this method.

Reimplemented in RuntimeSpriteObject.

virtual float RuntimeObject::GetDrawableY | ( | ) |  | const

inlinevirtual

Get the real Y position where is renderer the object.

Most of the time, this will return the same value as GetY().
However, some objects may allow the origin point to be moved: In this case, you need to redefine this method.

Reimplemented in RuntimeSpriteObject.

std::vector< Polygon2d > RuntimeObject::GetHitBoxes | ( | ) |  | const

virtual

Get the object hitbox(es)

Note
  Default implementation returns a basic bounding box, according to the object width/height and angle.

Reimplemented in RuntimeSpriteObject.

Here is the call graph for this function:

const std::string & RuntimeObject::GetVariableString | ( | const std::string & | variable) |  |

Only used internally by GD events generated code.

void RuntimeObject::Init | ( | const RuntimeObject & | object) |  |

protected

Initialize object using another object. Used by copy-ctor and assign-op.

Warning
  Don't forget to update me if members were changed !

virtual void RuntimeObject::OnPositionChanged | ( | ) |  |

inlinevirtual

Object can use this function to do special work when position is changed.

Reimplemented in RuntimeSpriteObject.

void RuntimeObject::SeparateFromObjects | ( | std::map< std::string, std::vector< RuntimeObject * > * > | pickedObjectLists) |  |

Only used internally by GD events generated code.

Here is the call graph for this function:

void RuntimeObject::SeparateObjectsWithForces | ( | std::map< std::string, std::vector< RuntimeObject * > * > | pickedObjectLists) |  |

Deprecated:

Here is the call graph for this function:

void RuntimeObject::SeparateObjectsWithoutForces | ( | std::map< std::string, std::vector< RuntimeObject * > * > | pickedObjectLists) |  |

Deprecated:

Here is the call graph for this function:

virtual bool RuntimeObject::SetAngle | ( | float | ) |  |

inlinevirtual

Get the angle of the object, in degrees.

The angle can be not changed if the object doesn't want/is not designed to.

Reimplemented in RuntimeSpriteObject.

virtual void RuntimeObject::SetHeight | ( | float | ) |  |

inlinevirtual

Set the new height of the object.

The height can be not changed if the object doesn't want/is not designed to.

Reimplemented in RuntimeSpriteObject.

virtual void RuntimeObject::SetWidth | ( | float | ) |  |

inlinevirtual

Set the new width of the object.

The width can be not changed if the object doesn't want/is not designed to.

Reimplemented in RuntimeSpriteObject.

void RuntimeObject::SetX | ( | float | x_) |  |

inline

Change X position of the object.

Note
  This method cannot be redefined: Redefine OnPositionChanged() to do extra work if needed.

void RuntimeObject::SetY | ( | float | y_) |  |

inline

Change Y position of the object.

Note
  This method cannot be redefined: Redefine OnPositionChanged() to do extra work if needed.

bool RuntimeObject::UpdateForce | ( | float | ElapsedTime) |  |

Automatically called at each frame so as to update forces applied on the object.

virtual void RuntimeObject::UpdateTime | ( | float | timeElapsed) |  |

inlinevirtual

Called at each frame so as to update internal object's things using time ( Such as animation for a sprite ).

Note
  The default implementation does nothing.

Reimplemented in RuntimeSpriteObject.

## Member Data Documentation

Force RuntimeObject::force5

Deprecated:
  Old custom force used to manage collisions.

The documentation for this class was generated from the following files:

- RuntimeObject.h
- RuntimeObject.cpp