RPG type "floating text"

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

RPG type "floating text"

Post by christianclavet »

Hi, done this function recently and used the Irrlicht animator to do most of the work. This was really easy to do and perhaps would like to do the same...

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);
    }
}
This will measure the node you use and create a animated text billboard that goes up and delete itself.

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));
Here is a screenshot of what it does visually:
Image
Last edited by christianclavet on Tue Feb 18, 2014 3:12 am, edited 1 time in total.
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: RPG type "floating text"

Post by thanhle »

Very useful!
Will use it for my project :).
Well done mate.
Mars_999
Posts: 136
Joined: Sat Dec 08, 2012 7:59 pm

Re: RPG type "floating text"

Post by Mars_999 »

Do you have a complete usage example of using this cool code? I am confused how to setup this code? getNode() no smgr to access it? I mean is this dropped into an overload class?

Ok here is what I put in to make it work but the text isnt' above the nodes position all the time sometimes it's off to the side?

Code: Select all

 
void CreateTextAnim(irr::scene::ISceneNode* node,
                    irr::core::stringw text = L"", 
                    irr::video::SColor color = irr::video::SColor(255, 255, 0, 0), 
                    irr::u32 duration = 2000, 
                    irr::core::dimension2d<f32> size = irr::core::dimension2d<f32>(18, 10))
{
    // 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
    //MYNODE->createTextAnim(L"Miss", video::SColor(255, 240, 120, 0), 3000, dimension2d<f32>(12, 8));
 
    NX::App& app = NX::App::Get();
 
    const wchar_t* ttext = L" ";
 
    if(!text.empty())
        ttext = text.c_str();
 
    irr::core::vector3df start = node->getAbsolutePosition();
    //irr::core::vector3df start = node->getPosition(); this places text above current node's position
 
    irr::f32 height = node->getBoundingBox().getExtent().Y * node->getScale().Y;
 
    start.Y += height - 30;
    irr::core::vector3df end = start;
    end.Y += height + 50;
 
    irr::scene::IBillboardTextSceneNode* nodetext = app.GetDevice()->getSceneManager()->addBillboardTextSceneNode(app.GetDevice()->getGUIEnvironment()->getBuiltInFont(), 
                ttext, node, size, start, -1, color, color);
 
    irr::scene::ISceneNodeAnimator* anim = app.GetDevice()->getSceneManager()->createDeleteAnimator(duration);
    irr::scene::ISceneNodeAnimator* anim2 = app.GetDevice()->getSceneManager()->createFlyStraightAnimator(start, end, duration);
    if(nodetext && anim)
    {
        nodetext->addAnimator(anim);
        nodetext->addAnimator(anim2);
    }
}
 
whoops I found it!

irr::core::vector3df start = node->getPosition(); use getPosition()!!
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: RPG type "floating text"

Post by christianclavet »

Oups! Your are right! Sorry! getNode() is from my own code and it not there! (Was in my APP class).

I edited the first post so that you give YOUR node as a parameter.
Post Reply