ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:    
Ambiera Forum > CopperCube > Programming and Scripting
NPC's names as 2D overlay
Author Text

rolevix
Registered User
Quote
2018-08-10 14:25:29

In "Multiplayer_2" behavior by jaimezegpi i found pretty awesome thing:

Names and messages of players makes out of 2D overlays and always move with players.

I was trying to make something using this plugin, but i am absolutely noob in JS.
I'm really needed this behavior to make interactive NPC's names with localization.

Any idea how i can make this, or some good sir can make this behavior for JS noobs like me? :)




tim12345
Guest
Quote
2018-08-10 15:46:31

hi, i think something like this might be what you are looking for...

var npc = ccbGetSceneNodeFromName("cubeMesh1");
var overlay = ccbGetSceneNodeFromName("2DOverlay1");
var npcPosition = ccbGetSceneNodeProperty(npc, "Position");
var pos = ccbGet2DPosFrom3DPos(npcPosition.x, npcPosition.y, npcPosition.z);
ccbSetSceneNodeProperty(overlay, "Pos X (pixels)", pos.x);
ccbSetSceneNodeProperty(overlay, "Pos Y (pixels)", pos.y);


every few seconds... 2d overlays must be set to absolute pixels...


rolevix
Registered User
Quote
2018-08-10 16:31:43

Thank you so much! Thats help me a lot :)


tim12345
Guest
Quote
2018-08-10 16:40:02

or maybe you want your 2D overlays to be relative (percent) ... then you will have to calculate something different like...
var npc = ccbGetSceneNodeFromName("cubeMesh1");
var overlay = ccbGetSceneNodeFromName("2DOverlay1");
var npcPosition = ccbGetSceneNodeProperty(npc, "Position");
var pos = ccbGet2DPosFrom3DPos(npcPosition.x, npcPosition.y, npcPosition.z);
var getW = ccbGetScreenWidth();
var getH = ccbGetScreenHeight();
var calW = pos.x/getW;
var calH = pos.y/getH;
ccbSetSceneNodeProperty(overlay, "Pos X (percent)", calW*100);
ccbSetSceneNodeProperty(overlay, "Pos Y (percent)", calH*100);



every few seconds javascript command... 2d overlays must be set to relative (percent)...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Int?rnational" (you are not logged in)


Text:

 

  

Forum Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   





Software: Ambiera Light Forum. © 2008-2018 Nikolaus Gebhardt, Ambiera e.U.