Here is the code:
Code: Select all
// Note: smgr = scene manager pointer is needed for manipulating and creating the elements
// Note: guienv = guienvironment pointer is needed for the font. You can also define your own font instead.
// Create and animate a text over the object head
void createTextAnim(scene::ISceneNode* node, core::stringw text=L"", video::SColor color=video::SColor(255,255,0,0), u32 duration=2000, dimension2d<f32> size=dimension2d<f32>(18,10));
{
const wchar_t * ttext = L" ";
if (!text.empty())
ttext=text.c_str();
vector3df start = node->getAbsolutePosition();
f32 height = node->getBoundingBox().getExtent().Y*getScale().Y;
start.Y+=height-30;
vector3df end = start;
end.Y+=height+50;
IBillboardTextSceneNode * nodetext = smgr->addBillboardTextSceneNode(guienv->getBuildInFont(),ttext,smgr->getRootSceneNode(),size,start,-1,color,color);
scene::ISceneNodeAnimator * anim = smgr->createDeleteAnimator(duration);
scene::ISceneNodeAnimator * anim2 = smgr->createFlyStraightAnimator(start,end,duration);
if (nodetext && anim)
{
nodetext->addAnimator(anim);
nodetext->addAnimator(anim2);
}
}
Here is an example on how to use it:
Code: Select all
createTextAnim(mynode, L"Miss",video::SColor(255,240,120,0),3000,dimension2d<f32>(12,8));