Jump to Main Content
Jump to Main Content

BlinkScript Text Code Example



Description


This code example shows how to draw 2D text that always faces the user. All the code and assets are in the projects Scripts directory. You can download the project using the link above.

PostWorld.js


// Turn on debug so that Chat.printDebug() and Chat.dump() work
Chat.debugOutput = true;

// Display the stats panel in the bottom left corner of screen
Application.statsVisible = true;

// Turn on collisions, but allow the user to turn it off
Actor.setCollisionSetting( true, false );

// Turn on gravity, but allow the user to turn it off
Actor.setGravitySetting( true, false );

// Hide the avatar
Actor.showAvatar  = false;

// Hide the chat panel
Application.chatPaneVisible = false;

// Set ambient light for the scene
Scene.ambientLightColor = Color(0.5, 0.5, 0.5, 0);

// Create a point light
// var oPointLight = Scene.createPointLight( "SceneLight" );
// oPointLight.position = Vector( 0, 600, -500 );

// Create the floor
var oGround = Scene.createGround( "MainFloor", "RustySteel", 3000.0, 3000.0, true );


// Add the Ogre head
oHeadEntity = Scene.createEntity( "OgreHead", "ogrehead.mesh" );
oHeadNode = Scene.createSceneNode( "OgreHeadNode" );
oHeadNode.attachObject( oHeadEntity );
oHeadNode.position = Vector( 0, 175, -500 );

// Create the text object
oText = Scene.createText( "MyText" );
oText.text = "Hello World\nThis text should be on\n3 lines.";

oText.alwaysOnTop = false;
// This text is using the default system font
// If you want to use a different font specify it here and
// add it to the Projects Scripts directory
// oText.fontName = "MyFont";
oText.spaceWidth = 14;
oText.additionalHeight = 100.0;
oText.horizAlignment = oText.TEXT_HORZ_ALIGN_CENTER;
oText.vertAlignment = oText.TEXT_VERT_ALIGN_ABOVE;

// Create scene node and attach text to it
oTextNode = Scene.createSceneNode( "MyTextNode" );
oTextNode.attachObject( oText );

// Set the position of the text in thw world
oTextNode.position = Vector( 0, 250, -500 );


// Create another text object
oText2 = Scene.createText( "MyText2" );
oText2.text = "This text should\nbe in a smaller font.";
oText2.alwaysOnTop = false;
oText2.characterHeight = 10;
oText2.spaceWidth = 8;

// Create a scene node, attach the text object and set position
oTextNode2 = Scene.createSceneNode( "MyTextNode2" );
oTextNode2.attachObject( oText2 );
oTextNode2.position = Vector( -150, 250, -500 );


Related BlinkScript Examples
?????? ?????? ?????? ??????