About Store Forum Documentation Contact



Post Reply 
Spawning NPC names
Author Message
WiLLyRS Offline
Member

Post: #1
Spawning NPC names
Hi, I have a little problem with the spawning of the other players and npc name above their head. I've done this and it works:

Code:
    for(int i=0; true; i++)        //printing NPCs names
    {
        NPCchar *temp = mWorld.getNPC(i);
        if (temp == false) break;
        Vec2 screen = PosToScreen(temp->pos());
        screen.y += 0.4f;
        D.text(screen, S + temp->name);
    }

my problem is that if I turn 180°, I'm still able to see their name. How can I control if I'm facing the right way?
(This post was last modified: 05-27-2011 02:33 PM by WiLLyRS.)
05-27-2011 02:32 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: Spawning NPC names
PosToScreenM()
05-27-2011 02:38 PM
Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #3
RE: Spawning NPC names
thanks ^^
05-27-2011 02:45 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #4
RE: Spawning NPC names
I'm doing it this way. It also prints the names of players smaller if they are further away and takes into account that not players have the same size. (Also my players can choose their avatar color, so each name is displayed in the same color as the player.)

According to Camera.h, PosToScreenM transforms by the current object matrix. But both functions have a variant with two arguments that returns false if the object is behind the camera.

PHP Code:
void cPeer::draw2D() {
    
// draw name of nearby characters
    
Flt distance 1.0f;
    if (
Players.elms()) {
        
Vec myPos Players[0].pos();
        
distance Dist(myPospos());
    }
    
Vec2 screen;
    if (
PosToScreen(pos() + Vec(0cskel.scale() * 0.75f0), screen)) {
        
tds.color color;
        
tds.scale 0.04 * (distance 10);
        if (
tds.scale.0.01) {
            
D.text(tdsscreenname);
        }
    }

(This post was last modified: 05-27-2011 11:51 PM by yvanvds.)
05-27-2011 11:47 PM
Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #5
RE: Spawning NPC names
lol i should have look better the functions, i wrote a function Dist() by myself XD
I was trying to do something like that but I was still trying to find a good "function" for the text scale pfft

D.text(tds, screen, name) tells me that the function doesn't match the arguments :(
05-28-2011 11:42 AM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #6
RE: Spawning NPC names
static void text(TextDS &tds, C Vec2 &p , CChar *t, Int max_length=-1);

tds is a TextDS, screen is Vec2, name was not clear in the example above but could be a Str. Actually the max_length variable could be interesting too, in case someone comes up with a very long username.
05-28-2011 12:07 PM
Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #7
RE: Spawning NPC names
Thanks, now I've adapted it to mine! I had to do D.text(tds,screen,name,-1), don't know why! smile
05-30-2011 11:34 AM
Find all posts by this user Quote this message in a reply
Post Reply