Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ime::GridObject Class Reference

An object that can be placed in a Grid2D. More...

#include <GridObject.h>

Inheritance diagram for ime::GridObject:
ime::GameObject ime::Object

Public Types

using Ptr = std::unique_ptr< GridObject >
 Unique game object pointer. More...
 
using BodyPtr = std::unique_ptr< RigidBody >
 Unique Body pointer. More...
 
using CollisionCallback = Callback< GameObject *, GameObject * >
 Collision callback. More...
 

Public Member Functions

 GridObject (Scene &scene)
 Constructor. More...
 
 GridObject (const GridObject &)
 Copy constructor. More...
 
GridObjectoperator= (const GridObject &)
 Copy assignment operator. More...
 
 GridObject (GridObject &&) noexcept=default
 Move constructor. More...
 
GridObjectoperator= (GridObject &&) noexcept=default
 Move assignment operator. More...
 
GridObject::Ptr copy () const
 Create a copy of the game object. More...
 
void swap (GridObject &other)
 Swap the object with another game object. More...
 
std::string getClassName () const override
 Get the name of the class the game object is instantiated from. More...
 
void setDirection (const Vector2i &dir)
 Set the direction of the object. More...
 
const Vector2igetDirection () const
 Get the objects current direction. More...
 
void setObstacle (bool isObstacle)
 Set whether or not the game object is an obstacle. More...
 
bool isObstacle () const
 Check if the object is an obstacle or not. More...
 
void setCollisionId (int id)
 Set the game objects collision id. More...
 
int getCollisionId () const
 Get the collision id. More...
 
void setCollisionGroup (const std::string &name)
 Set the objects collision group. More...
 
const std::string & getCollisionGroup () const
 Get the objects collision group. More...
 
void setSpeed (const Vector2f &speed)
 Set the speed of the game object. More...
 
const Vector2fgetSpeed () const
 Get the speed of the target. More...
 
bool isMoving () const
 Check if target is moving or not. More...
 
Index getGridIndex () const
 Get the index of the grid tile currently occupied by the object. More...
 
Grid2DgetGrid ()
 Get access to the grid in which the target is moved in. More...
 
const Grid2DgetGrid () const
 
ExcludeListgetCollisionExcludeList ()
 Get the game objects collision exclude list. More...
 
const ExcludeListgetCollisionExcludeList () const
 
ExcludeListgetObstacleCollisionFilter ()
 Get the game objects obstacle collision filter. More...
 
const ExcludeListgetObstacleCollisionFilter () const
 
GridMovergetGridMover ()
 Get the objects grid mover. More...
 
const GridMovergetGridMover () const
 
int onGridEnter (const Callback< GridObject * > &callback, bool oneTime=false)
 Add an event listener to a grid enter event. More...
 
int onGridExit (const Callback< GridObject * > &callback, bool oneTime=false)
 Add an event listener to a grid exit event. More...
 
int onGridMoveBegin (const Callback< GridObject * > &callback, bool oneTime=false)
 Add an event listener to a move begin event. More...
 
int onGridPreMove (const Callback< GridObject * > &callback, bool oneTime=false)
 Add an event listener to a pre move event. More...
 
int onGridPostMove (const Callback< GridObject * > &callback, bool oneTime=false)
 Add an event listener to a grid move event. More...
 
int onGridMoveEnd (const Callback< GridObject * > &callback, bool oneTime=false)
 Add an event listener to an adjacent tile reached event. More...
 
int onGridObjectCollision (const Callback< GridObject *, GridObject * > &callback, bool oneTime=false)
 Add an event listener to a grid object collision event. More...
 
int onGridBorderCollision (const Callback< GridObject * > &callback, bool oneTime=false)
 Add an event listener to a grid border collision event. More...
 
int onGridTileCollision (const Callback< GridObject *, Index > &callback, bool oneTime=false)
 Add an event listener to a grid tile collision event. More...
 
void setGridMover (GridMover *gridMover)
 
void setGrid (Grid2D *grid)
 
void emitGridEvent (const Property &property)
 
 ~GridObject () override
 Destructor. More...
 
void swap (GameObject &other)
 Swap the game object with another game object. More...
 
void setState (int state)
 Set current state. More...
 
int getState () const
 Get the current state of the game object. More...
 
void setActive (bool isActive)
 Set whether or not the game object is active. More...
 
bool isActive () const
 Check if the game object is active or not. More...
 
PropertyContainergetUserData ()
 Get the user data added to game object. More...
 
const PropertyContainergetUserData () const
 
std::string getClassType () const override
 Get the name of this class. More...
 
void attachRigidBody (BodyPtr body)
 Attach a physics Body to the game object. More...
 
RigidBodygetRigidBody ()
 Get the game objects physics body. More...
 
const RigidBodygetRigidBody () const
 
void removeRigidBody ()
 Remove a rigid body from the game object. More...
 
bool hasRigidBody () const
 Check if the the game object has a rigid body attached to it. More...
 
int onRigidBodyCollisionStart (const CollisionCallback &callback, bool oneTime=false)
 Add an event listener to a rigid body collision begin event. More...
 
int onRigidBodyCollisionEnd (const CollisionCallback &callback, bool oneTime=false)
 Add an event listener to a rigid body collision end event. More...
 
int onRigidBodyCollisionStay (const CollisionCallback &callback, bool oneTime=false)
 Add an event listener to a rigid body collision stay event. More...
 
TransformgetTransform ()
 Get the game objects transform. More...
 
const TransformgetTransform () const
 
ScenegetScene ()
 Get the scene the game object belongs to. More...
 
const ScenegetScene () const
 
void resetSpriteOrigin ()
 Reset the origin of the sprite. More...
 
SpritegetSprite ()
 Get the game objects graphical representation. More...
 
const SpritegetSprite () const
 
virtual void update (Time deltaTime)
 Update the game object. More...
 
void emitRigidBodyCollisionEvent (const std::string &event, GameObject *other)
 
void setTag (const std::string &tag)
 Assign the object an alias. More...
 
const std::string & getTag () const
 Get the tag assigned to the object. More...
 
unsigned int getObjectId () const
 Get the unique id of the object. More...
 
int onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to a specific property change event. More...
 
int onPropertyChange (const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to any property change event. More...
 
void suspendedEventListener (int id, bool suspend)
 Pause or resume execution of an event listener. More...
 
bool isEventListenerSuspended (int id) const
 Check if an event listener is suspended or not. More...
 
bool removeEventListener (const std::string &event, int id)
 Remove an event listener from an event. More...
 
bool removeEventListener (int id)
 Remove an event listener. More...
 
int onDestruction (const Callback<> &callback)
 Add a destruction listener. More...
 
bool isSameObjectAs (const Object &other) const
 Check if another object is the same instance as this object. More...
 

Static Public Member Functions

static GridObject::Ptr create (Scene &scene)
 Create a new GridObject instance. More...
 

Protected Member Functions

void emitChange (const Property &property)
 Dispatch a property change event. More...
 
void emitDestruction ()
 Emit a destruction event. More...
 

Protected Attributes

EventEmitter eventEmitter_
 Event dispatcher. More...
 

Detailed Description

An object that can be placed in a Grid2D.

Definition at line 40 of file GridObject.h.

Member Typedef Documentation

◆ BodyPtr

using ime::GameObject::BodyPtr = std::unique_ptr<RigidBody>
inherited

Unique Body pointer.

Definition at line 45 of file GameObject.h.

◆ CollisionCallback

Collision callback.

Definition at line 46 of file GameObject.h.

◆ Ptr

using ime::GridObject::Ptr = std::unique_ptr<GridObject>

Unique game object pointer.

Definition at line 42 of file GridObject.h.

Constructor & Destructor Documentation

◆ GridObject() [1/3]

ime::GridObject::GridObject ( Scene scene)
explicit

Constructor.

Parameters
sceneThe scene this game object belongs to

◆ GridObject() [2/3]

ime::GridObject::GridObject ( const GridObject )

Copy constructor.

◆ GridObject() [3/3]

ime::GridObject::GridObject ( GridObject &&  )
defaultnoexcept

Move constructor.

◆ ~GridObject()

ime::GridObject::~GridObject ( )
override

Destructor.

Member Function Documentation

◆ attachRigidBody()

void ime::GameObject::attachRigidBody ( BodyPtr  body)
inherited

Attach a physics Body to the game object.

Parameters
bodyPhysics body to be attached to the game object

When a rigid body is attached to a game object, the game object becomes enabled for physics. This means that it will react to gravity, friction, applies forces, impulses etc. The position and rotation of the game object will be controlled by the physics engine therefore you should refrain from calling functions that MODIFY the game objects transform (position, rotation and origin). A result of doing so is inconsistency. Note that the physics engine does not account for scaling. This means that scaling the objects sprite will NOT scale the objects body or the body's collider. If you want the body to scale with the objects sprite, you should remove the old collider and attach a new one with the appropriate size.

Warning
The pointer must not be a nullptr. Also, you cannot attach a rigid body to a game object that already has a rigid body attached to it, the current rigid body must be removed first
See also
removeRigidBody

◆ copy()

GridObject::Ptr ime::GridObject::copy ( ) const

Create a copy of the game object.

Returns
A new game object

◆ create()

static GridObject::Ptr ime::GridObject::create ( Scene scene)
static

Create a new GridObject instance.

Parameters
sceneThe scene the object belongs to
Returns
The created instance

◆ emitChange()

void ime::Object::emitChange ( const Property property)
protectedinherited

Dispatch a property change event.

Parameters
propertyThe property that changed

This function will invoke all the event listeners of the specified property

See also
emit

◆ emitDestruction()

void ime::Object::emitDestruction ( )
protectedinherited

Emit a destruction event.

Note
This function must be the first statement in the definition of a destructor to avoid undefined behavior. In addition, note that destruction listeners are invoked once. Therefore, multiple classes in a hierarchy may call this function but the class that makes the call first will be the one that invokes the destruction listeners

◆ getClassName()

std::string ime::GridObject::getClassName ( ) const
overridevirtual

Get the name of the class the game object is instantiated from.

Returns
The name of the concrete class the game object is instantiated from

Note that this function must be overridden further if this class is extended, otherwise it will return the name of this class instead of your class name

See also
getClassType

Reimplemented from ime::GameObject.

◆ getClassType()

std::string ime::GameObject::getClassType ( ) const
overridevirtualinherited

Get the name of this class.

Returns
The name of this class

Note that this function is only implemented by child classes of Object which also serve as a base class for other classes

See also
getClassName

Reimplemented from ime::Object.

◆ getCollisionExcludeList()

ExcludeList & ime::GridObject::getCollisionExcludeList ( )

Get the game objects collision exclude list.

Returns
The game objects collision exclude list

This list allows you to specify which game objects this game object can collide with

By default, the game object collides with all other objects

See also
getObstacleCollisionFilter

◆ getCollisionGroup()

const std::string & ime::GridObject::getCollisionGroup ( ) const

Get the objects collision group.

Returns
The game objects collision group
See also
setCollisionGroup

◆ getCollisionId()

int ime::GridObject::getCollisionId ( ) const

Get the collision id.

Returns
The objects collision id
See also
setCollisionId

◆ getDirection()

const Vector2i & ime::GridObject::getDirection ( ) const

Get the objects current direction.

Returns
The objects direction

◆ getGrid()

Grid2D * ime::GridObject::getGrid ( )

Get access to the grid in which the target is moved in.

Returns
The grid in which the target is being moved in

◆ getGridIndex()

Index ime::GridObject::getGridIndex ( ) const

Get the index of the grid tile currently occupied by the object.

Returns
The index of the grid tile currently occupied by the object

Note that when the object is moved by a GridMover, it occupies a tile ahead of time, see ime::GridMover::requestMove()

This function returns ime::Index{-1, -1} if the object is not in a Grid

See also
getPrevTileIndex

◆ getGridMover()

GridMover * ime::GridObject::getGridMover ( )

Get the objects grid mover.

Returns
The objects grid mover or a nullptr if the object is not being controlled by a grid mover
See also
ime::GridMover

◆ getObjectId()

unsigned int ime::Object::getObjectId ( ) const
inherited

Get the unique id of the object.

Returns
The unique id of the object

Note that each instance of ime::Object has a unique id

See also
setTag

◆ getObstacleCollisionFilter()

ExcludeList & ime::GridObject::getObstacleCollisionFilter ( )

Get the game objects obstacle collision filter.

Returns
The game objects obstacle collision filter

By default, any object that cannot collide with an obstacle game object will pass through it without generating a collision event whereas if they can collide, the two objects will never overlap. Sometimes you may want an obstacle object to exhibit the default behavior for some objects but allow others to pass through it and still generate a collision event. This list helps you achieve that. The collision groups of game objects added to this list will pass over an obstacle game object but generate a collision event

Note
This function is useful only if the game object is an obstacle (see setObstacle()).
See also
getCollisionExcludeList

◆ getRigidBody()

RigidBody * ime::GameObject::getRigidBody ( )
inherited

Get the game objects physics body.

Returns
The game objects physics body if any, otherwise a nullptr

◆ getScene()

Scene & ime::GameObject::getScene ( )
inherited

Get the scene the game object belongs to.

Returns
The scene the game object belongs to

◆ getSpeed()

const Vector2f & ime::GridObject::getSpeed ( ) const

Get the speed of the target.

Returns
The speed of the target
See also
setSpeed

◆ getSprite()

Sprite & ime::GameObject::getSprite ( )
inherited

Get the game objects graphical representation.

Returns
The game objects graphical representation

By default, the sprite is empty

◆ getState()

int ime::GameObject::getState ( ) const
inherited

Get the current state of the game object.

Returns
The current state of the game object

◆ getTag()

const std::string & ime::Object::getTag ( ) const
inherited

Get the tag assigned to the object.

Returns
The tag of the object
See also
setTag

◆ getTransform()

Transform & ime::GameObject::getTransform ( )
inherited

Get the game objects transform.

Returns
The game objects transform

The transform can be used to query or modify the game object position, scale, rotation and origin

◆ getUserData()

PropertyContainer & ime::GameObject::getUserData ( )
inherited

Get the user data added to game object.

Returns
The user data

The user data object can be used to store additional information about the game object. For example, you may store a profile associated with the game object or when the game object was instantiated etc... You can store any type and any number of data in the user date object

Note that IME does not store anything inside the user data object, it is reserved for external use only

◆ hasRigidBody()

bool ime::GameObject::hasRigidBody ( ) const
inherited

Check if the the game object has a rigid body attached to it.

Returns
True if the game object has a rigid body attached to it, otherwise false

◆ isActive()

bool ime::GameObject::isActive ( ) const
inherited

Check if the game object is active or not.

Returns
True if the game object is active, otherwise false
See also
setActive

◆ isEventListenerSuspended()

bool ime::Object::isEventListenerSuspended ( int  id) const
inherited

Check if an event listener is suspended or not.

Parameters
idThe identification number of the listener to be checked
Returns
True if suspended, otherwise false

This function also returns false if the specified event listener does not exist

See also
suspendedEventListener

◆ isMoving()

bool ime::GridObject::isMoving ( ) const

Check if target is moving or not.

Returns
True if target is moving otherwise false
See also
getTarget

◆ isObstacle()

bool ime::GridObject::isObstacle ( ) const

Check if the object is an obstacle or not.

Returns
True if the object is an obstacle, otherwise false
See also
setObstacle

◆ isSameObjectAs()

bool ime::Object::isSameObjectAs ( const Object other) const
inherited

Check if another object is the same instance as this object.

Parameters
otherThe object to compare against this object
Returns
True if other is the same instance as this object, otherwise false

◆ onDestruction()

int ime::Object::onDestruction ( const Callback<> &  callback)
inherited

Add a destruction listener.

Parameters
callbackFunction to be executed when the object is destroyed
Returns
The unique id of the destruction listener

The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it

Warning
It's not advised to call virtual functions in the destruction callback as some parts of the object may have already been destroyed by the time the callback is invoked. In such an event, the behavior is undefined
See also
removeEventListener

◆ onGridBorderCollision()

int ime::GridObject::onGridBorderCollision ( const Callback< GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to a grid border collision event.

Parameters
callbackFunction to execute when the collision takes place
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners identification number

This event is emitted when the target tries to go beyond the bounds of the grid. By default the event is handled internally before it's emitted to the outside. The internal handler prevents the target from leaving the grid. That is, the target will occupy the same tile it occupied before the collision. This behaviour is not removable, however, it may be overridden since the internal handler is called first before alerting external handlers

The callback is passed this object on invocation

See also
unsubscribe

◆ onGridEnter()

int ime::GridObject::onGridEnter ( const Callback< GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to a grid enter event.

Parameters
callbackThe function to be executed when the game object is added to a Grid2D
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners unique identification number

The callback is passed this game object on invocation

See also
onGridExit

◆ onGridExit()

int ime::GridObject::onGridExit ( const Callback< GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to a grid exit event.

Parameters
callbackThe function to be executed when the game object is removed from a Grid2D
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners unique identification number

The callback is passed this game object on invocation

See also
onGridEnter

◆ onGridMoveBegin()

int ime::GridObject::onGridMoveBegin ( const Callback< GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to a move begin event.

Parameters
callbackThe function to be executed when the game object starts moving
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners unique identification number

This event is emitted when the game object starts moving from its current tile to one of its adjacent tile. The callback is passed the index of the tile that the game object is currently moving to

Note
When controlled by a grid mover, the game object will always move one tile at a time, regardless of how fast it's moving

The callback is passed this game object on invocation

See also
onGridMoveEnd

◆ onGridMoveEnd()

int ime::GridObject::onGridMoveEnd ( const Callback< GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to an adjacent tile reached event.

Parameters
callbackFunction to execute when the target reaches its target tile
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners identification number

This event is emitted when the target moves from its current tile to any of its adjacent tiles.

Note
When controlled by a grid mover, the target will always move one tile at a time, regardless of how fast the target is moving

The callback is passed this game object on invocation

See also
onGridMoveBegin

◆ onGridObjectCollision()

int ime::GridObject::onGridObjectCollision ( const Callback< GridObject *, GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to a grid object collision event.

Parameters
callbackFunction to be executed when this game object collides with another game object in a Grid2D
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners unique identification number

This event is triggered when this grid object collides with another grid object or vice versa. A collision is registered between two grid objects when the occupy the same Grid2D tile

The callback is passed this game object and the game object it is in collision with respectively.

See also
removeCollisionListener

◆ onGridPostMove()

int ime::GridObject::onGridPostMove ( const Callback< GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to a grid move event.

Parameters
callbackThe function to be executed after the object moves in the grid
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners unique identification number

This event is fired every time after the object moves in the grid. The difference between onGridMoveEnd() and onGridPostMove() is that the former is called once at the end of the tile movement and the latter is called every time after the objects position is updated while in transit to its target tile.

You can add as many event listeners as you want to this event. Furthermore, the callback is passed this game object on invocation

Note
This event is only fired if the object does not have a RigidBody attached to it. see GameObject::attachRigidBody
See also
onGridPreMove, onGridMoveBegin, onGridMoveEnd

◆ onGridPreMove()

int ime::GridObject::onGridPreMove ( const Callback< GridObject * > &  callback,
bool  oneTime = false 
)

Add an event listener to a pre move event.

Parameters
callbackThe function to be executed before the object is moved in the grid
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners unique identification number

This event is fired every time the object is about to move in the grid. The difference between onGridMoveBegin() and onGridPreMove() is that the former is called once per tile movement and the latter is called every time the objects position is about to be updated while in transit to its target tile. In other words, onGridMoveBegin() is called at the beginning of the tile movement and onGridPreMove() is called until the object completes its tile movement.

You can add as many event listeners as you want to this event. Furthermore, the callback is passed this game object on invocation

Note
This event is only fired if the object does not have a RigidBody attached to it. see GameObject::attachRigidBody
See also
onGridMove

◆ onGridTileCollision()

int ime::GridObject::onGridTileCollision ( const Callback< GridObject *, Index > &  callback,
bool  oneTime = false 
)

Add an event listener to a grid tile collision event.

Parameters
callbackFunction to execute when the collision takes place
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners identification number

This event is emitted when the object collides with a grid tile By default, the event is handled internally before its emitted. The internal handler prevents the object from occupying the tile by moving it back to its previous tile. This behaviour is not removable, however, it may be overridden since the internal handler is called first before alerting external handlers

The callback is passed this object and the index of the tile it tried to occupy on invocation

See also
unsubscribe

◆ onPropertyChange() [1/2]

int ime::Object::onPropertyChange ( const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to any property change event.

Parameters
callbackThe function to be executed when any property changes
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The unique id of the event listener

When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event

See also
onPropertyChange(const std::string&, const ime::Callback<ime::Property>&)

◆ onPropertyChange() [2/2]

int ime::Object::onPropertyChange ( const std::string &  property,
const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to a specific property change event.

Parameters
propertyThe name of the property to add an event listener to
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
callbackThe function to be executed when the property changes
Returns
The unique id of the event listener

A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called

Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.

// Prints the tag of the player object to the console everytime it changes
player.onPropertyChange("tag", [](const Property& property) {
cout << "New tag: " << property.getValue<std::string>() << endl;
});
...
//Sets tag = "player1" and invokes event listener(s)
player.setTag("player1");
See also
unsubscribe and onPropertyChange(const ime::Callback<ime::Property>&)

◆ onRigidBodyCollisionEnd()

int ime::GameObject::onRigidBodyCollisionEnd ( const CollisionCallback callback,
bool  oneTime = false 
)
inherited

Add an event listener to a rigid body collision end event.

Parameters
callbackThe function to be executed when the event is fired
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners identification number

The callback function is called when two game objects stop overlapping. The callback is passed this game object and the game object that stopped overlapping with this game object respectively.

A collision end handler may be registered on the game object or on the collider that is attached to the game objects rigid body or on both. However, exercise caution as registering the same handler on both objects will result in the handler being executed twice each time the event is fired

Note
A collision end event can only occur if the game object has a rigid body attached to it and the rigid body has a Collider attached to it
See also
attachRigidBody, onCollisionStart and onCollisionStay

◆ onRigidBodyCollisionStart()

int ime::GameObject::onRigidBodyCollisionStart ( const CollisionCallback callback,
bool  oneTime = false 
)
inherited

Add an event listener to a rigid body collision begin event.

Parameters
callbackThe function to be executed when the event is fired
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners identification number

The callback function is called when two game objects begin to overlap. The callback is passed this game object and the game object that collided with this game object respectively.

A collision begin handler may be registered on the game object or on the collider that is attached to the game objects rigid body or on both. However, exercise caution as registering the same handler on both objects will result in the handler being executed twice each time the event is fired

Note
A collision begin event can only occur if the game object has a rigid body attached to it and the rigid body has a Collider attached to it
See also
attachRigidBody, onCollisionStay and onCollisionEnd

◆ onRigidBodyCollisionStay()

int ime::GameObject::onRigidBodyCollisionStay ( const CollisionCallback callback,
bool  oneTime = false 
)
inherited

Add an event listener to a rigid body collision stay event.

Parameters
callbackThe function to be executed when the event is fired
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners identification number

The callback function is called while this game object remains in contact with another game object. The callback is passed this game object and the game object that is currently in contact with this game object respectively.

A collision stay handler may be registered on the game object or on the collider that is attached to the game objects rigid body or on both. However, exercise caution as registering the same handler on both objects will result in the handler being executed twice each time the event is fired

Note
A collision stay event can only occur if the game object has a rigid body attached to it and the rigid body is awake and has a Collider attached to it that is not a sensor
See also
attachRigidBody, onCollisionStart and onCollisionEnd

◆ operator=() [1/2]

GridObject & ime::GridObject::operator= ( const GridObject )

Copy assignment operator.

◆ operator=() [2/2]

GridObject & ime::GridObject::operator= ( GridObject &&  )
defaultnoexcept

Move assignment operator.

◆ removeEventListener() [1/2]

bool ime::Object::removeEventListener ( const std::string &  event,
int  id 
)
inherited

Remove an event listener from an event.

Parameters
eventThe name of the event to remove an event listener from
idThe unique id of the event listener to be removed
Returns
True if the event listener was removed or false if the event or the event listener is does not exist
// Display the tag of the object to console every time it changes
auto tagChangeId = object.onPropertyChange("tag", [](ime::Property tag) {
std::cout << name.getValue<std::string>() << std::endl;
});
// Stop displaying the tag of the object when it changes
object.removeEventListener("tag", tagChangeId);
Class that can store a value of any type.
Definition: Property.h:38

◆ removeEventListener() [2/2]

bool ime::Object::removeEventListener ( int  id)
inherited

Remove an event listener.

Parameters
idThe id of the event listener to be removed
Returns
True if the event listener was removed or false if no such handler exists

◆ removeRigidBody()

void ime::GameObject::removeRigidBody ( )
inherited

Remove a rigid body from the game object.

Removing a rigid Body from an game object disables all physics applied to it

See also
attachRigidBody

◆ resetSpriteOrigin()

void ime::GameObject::resetSpriteOrigin ( )
inherited

Reset the origin of the sprite.

The origin is reset to the local centre of the sprite

Note
This function must be called everytime the sprites texture, texture rectangle size or scale is changed

◆ setActive()

void ime::GameObject::setActive ( bool  isActive)
inherited

Set whether or not the game object is active.

Parameters
isActiveTrue to set as active or false to set as inactive

Note that an inactive game object does not participate in collision detection. In addition the game object's update() method will not be invoked.

By default, the object is active

See also
isActive

◆ setCollisionGroup()

void ime::GridObject::setCollisionGroup ( const std::string &  name)

Set the objects collision group.

Parameters
nameThe collision group to be set

A collision group allows certain game objects to always collide or never collide with each other. When a collision group is added to the object's collision exclusion list (see getCollisionExcludeList()), the game object will never collide with game objects in that group (they will pass through each other without generating a collision event), whereas when not added, the game object will always collide with game objects whose collision group does not appear in its exclusion list

Note that the active state (see ime::GameObject::setActive()) takes higher precedence than "collision group" filtering. This means that, regardless of how the collision groups are configured, a collision will never take place if the game object is not active

For example, the following code makes objects in the "Enemies" collision group to never collide with each other:

// Assume 'enemies' is a collection of 'ime::GridObject' objects
for (auto& enemy : enemies) {
enemy.setCollisionGroup("Enemies");
enemy.getCollisionExcludeList().add("Enemies");
}

By default, the collision group is am empty string. This means that the object does not belong to any collision group. Therefore, it will collide with any other game object whose collision id is the same as theirs

See also
getCollisionGroup, setCollisionId and getCollisionExcludeList

◆ setCollisionId()

void ime::GridObject::setCollisionId ( int  id)

Set the game objects collision id.

Parameters
idThe id to be set

A collision id allows game objects to selectively collide with each other within colliding groups (see setCollisionGroup()). Game objects with the same collision id will collide with each other, whilst game objects with different collision id's do not collide with each other.

Note that "collision group" filtering takes higher precedence than "collision id" filtering. This means that regardless of how collision id's are configured, a collision will never take place if the collision group of one game object is added to the other game objects collision group exclude list (see getCollisionExcludeList())

By default, the collision id is 0. This means that this game object will collide with any other game object that is not in its collision group exclude list

See also
setCollisionGroup and getCollisionExcludeList

◆ setDirection()

void ime::GridObject::setDirection ( const Vector2i dir)

Set the direction of the object.

Parameters
dirThe direction to be set

By default the direction is Vector2i{0, 0}

See also
getDirection

◆ setObstacle()

void ime::GridObject::setObstacle ( bool  isObstacle)

Set whether or not the game object is an obstacle.

Parameters
isObstacleTrue if it is an obstacle, otherwise false

When the object is an obstacle and its active state is true (see ime::GameObject::setActive), then other game objects cannot overlap with it. A collision event will be raised when another game object attempts to occupy the same cell as the obstacle. However, the two objects will never overlap

By default, the game object is not an obstacle

See also
isObstacle

◆ setSpeed()

void ime::GridObject::setSpeed ( const Vector2f speed)

Set the speed of the game object.

Parameters
speedThe new speed

By default, the speed is ime::Vector2f{0, 0}

See also
getSpeed

◆ setState()

void ime::GameObject::setState ( int  state)
inherited

Set current state.

Parameters
stateThe current state

The state is number that should be associated with something (maybe an enum) in your game.

Be default, the state is -1, which is supposed to indicate that there is no state. The state property is optional and may be used if needs be. It is not used by IME

◆ setTag()

void ime::Object::setTag ( const std::string &  tag)
inherited

Assign the object an alias.

Parameters
tagThe alias of the object

This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag

By default, the tag is an empty string

See also
getObjectId

◆ suspendedEventListener()

void ime::Object::suspendedEventListener ( int  id,
bool  suspend 
)
inherited

Pause or resume execution of an event listener.

Parameters
idThe event listeners unique identification number
suspendTrue to suspend/pause or false to unsuspend/resume
See also
isEventListenerSuspended

◆ swap() [1/2]

void ime::GameObject::swap ( GameObject other)
inherited

Swap the game object with another game object.

Parameters
otherThe game object to swap with this game object

◆ swap() [2/2]

void ime::GridObject::swap ( GridObject other)

Swap the object with another game object.

Parameters
otherThe object to swap with this game object

◆ update()

virtual void ime::GameObject::update ( Time  deltaTime)
inlinevirtualinherited

Update the game object.

Parameters
deltaTimeTime past since last update

This function is automatically called by IME. deltaTime is synced with the render FPS. In other words, it is frame-rate dependent.

Note that this function is provided for external use only, IME will never put anything inside it. This means that don't have to call the base class version when overriding it

Definition at line 346 of file GameObject.h.

Member Data Documentation

◆ eventEmitter_

EventEmitter ime::Object::eventEmitter_
protectedinherited

Event dispatcher.

Definition at line 289 of file Object.h.


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