Expand ShapeBase::sethidden
by Caylo Gypsyblood · in Torque Game Engine · 08/20/2007 (11:59 am) · 1 replies
In my project i have lots of pickup items that also have particle FX to support the item mesh. I was havening trouble in my item::onCollision call, setting the item.setHidden(true); was fine for getting the item out of the way, and being the item::OnAdd can create one emitter using item.particle = new ParticleEmitterNode simply using item.particle.delete(); would clear out that particle( not a very dynamic and flexible way to do this..). But i find no easy way to add the particle back when using the item.Respawn(); call.
There may be an much easy way to do this, but i decided to add in SHAPEBASE::onvisable(); and SHAPEBASE::onhidden(); script callbacks. Now when i call THING.sethidden(true); the THING::onhidden(); call is made, where i have a function to turn off emitters, play a sound FX, ect. When the THING.sethidden(false); is made, The extra FX can be re-activated using SHAPEBASE::onvisable(); function.
The magic is:
Con::executef(mDataBlock,3,"onvisable",scriptThis(),Con::getIntArg(mDataBlock->getId())); And may be used in any number of places to add script callbacks for any number of conditions.
SHAPEBASE.CC
There may be an much easy way to do this, but i decided to add in SHAPEBASE::onvisable(); and SHAPEBASE::onhidden(); script callbacks. Now when i call THING.sethidden(true); the THING::onhidden(); call is made, where i have a function to turn off emitters, play a sound FX, ect. When the THING.sethidden(false); is made, The extra FX can be re-activated using SHAPEBASE::onvisable(); function.
The magic is:
Con::executef(mDataBlock,3,"onvisable",scriptThis(),Con::getIntArg(mDataBlock->getId())); And may be used in any number of places to add script callbacks for any number of conditions.
SHAPEBASE.CC
void ShapeBase::setHidden(bool hidden)
{
if (hidden != mHidden)
{
// need to set a mask bit to make the ghost manager delete copies of this object
// hacky, but oh well.
setMaskBits(CloakMask);
if (mHidden)
{
addToScene();
Con::executef(mDataBlock,3,"onvisable",scriptThis(),Con::getIntArg(mDataBlock->getId()));
}
else
{
removeFromScene();
Con::executef(mDataBlock,3,"onhidden",scriptThis(),Con::getIntArg(mDataBlock->getId()));
}
mHidden = hidden;
}
}
Associate Matt Fairfax
PopCap