Getting the Player Object
by Daniel Neilsen · in Torque Game Engine · 10/26/2001 (6:27 am) · 2 replies
I have this function
void GuiEnergyBarVertHud::onRender(Point2I offset, const RectI &updateRect)
{
GameConnection* conn = GameConnection::getServerConnection();
if (!conn)
return;
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & PlayerObjectType))
return;
mValue = 1 - control->getEnergyValue();
but, instead of running the function ShapeBase::getEnergyValue() for the shapebase I want to run Player::getEnergyValue().
I have the gameconnection and the shapebase. How can I get the player from these?
void GuiEnergyBarVertHud::onRender(Point2I offset, const RectI &updateRect)
{
GameConnection* conn = GameConnection::getServerConnection();
if (!conn)
return;
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & PlayerObjectType))
return;
mValue = 1 - control->getEnergyValue();
but, instead of running the function ShapeBase::getEnergyValue() for the shapebase I want to run Player::getEnergyValue().
I have the gameconnection and the shapebase. How can I get the player from these?
About the author
Associate Mark Frohnmayer
Player *controlPlayer = dynamic_cast
if(controlPlayer)
mValue = 1 - controlPlayer->getEnergyValue();
or, you could do a static cast if you know for sure that the control object is a player.