This code example shows how to create a very simple environment with a ground, skydome, pointlight and a cube. The cube is rotated using a timestemp.
It also shows the typical initial setup for debugging, collisions, stats and gravity.
All the code and assets are in the projects Scripts directory. You can download the project using the link above.
// 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 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 a Skydome
var oSkyDome = Scene.createSkyDome();
oSkyDome.materialName = "CloudySky";
oSkyDome.curvature = 5;
oSkyDome.tiling = 8;
oSkyDome.distance = 4000;
oSkyDome.enable = true;
// Create the floor
var oGround = Scene.createGround( "MainFloor", "RustySteel", 3000.0, 3000.0, true );
// Add the cube
// Create and entity
var oCubeEntity = Scene.createEntity( "Cube_SM_small", "Cube_SM_small.mesh" );
// Create a scen node
var oCubeNode = Scene.createSceneNode( "Cube_SM_smallNode" );
// Add the entity to the scene node
oCubeNode.attachObject( oCubeEntity );
// Set the position of the scenenode and therefore the entity
oCubeNode.position = Vector( 0, 300, -500 );
// Create a timestep to rotate the cube
var oTimestep = new Object();
oTimestep.dRotationAmount = 0;
oTimestep.oParent = this;
oTimestep.timestep = function( dElapsedTime, dDeltaTime )
{
// Increment the amount to rotate the cube by the amount of
// time that has elapsed sine the timestep was last called
this.dRotationAmount += dDeltaTime;
// Change the orientation of the cube
this.oParent.oCubeNode.orientation = Rotation( 'Y', this.dRotationAmount );
}
// Add the timestep
Application.addTimestep( oTimestep );