CopperCube JavaScript reference
(Under Construction)

Note:- This page is currently  being under construction. Information available on this page might not be accurate and complete.


CopperCube provides a very simple interface to manipulate all aspects of a 3D scene. This page lists all available functions.
Most of these functions manipulate so called 'scene nodes'. A scene node is nothing more than a 3d object with a position, rotation, scale, its materials and childrens. The name 'scene node' is there because CopperCube is internally using a scene graph to represent the 3d scene.

Here is the list of JavaScript functions, each function is marked with icons that represent the platform on which that function will work. Functions marked with icon will work in Windows client,  will work in webGL and  will work in CopperCube Editor. If you don't see a specific icon in front of a function then it means that functions doesn't work on that platform.


Scene Node Handling

ccbCloneSceneNode  
ccbGetActiveCamera
ccbSetActiveCamera
ccbGetChildSceneNode
ccbGetRootSceneNode
ccbGetSceneNodeChildCount
ccbGetSceneNodeProperty
ccbSetSceneNodeProperty
ccbGetSceneNodeFromName
ccbGetSceneNodeMaterialCount
ccbGetSceneNodeMaterialProperty
ccbSetSceneNodeMaterialProperty
ccbRemoveSceneNode
ccbSetSceneNodeParent
ccbSetSceneNodePositionWithoutCollision

Events

ccbRegisterKeyDownEvent
ccbRegisterKeyUpEvent
ccbRegisterMouseDownEvent
ccbRegisterMouseUpEvent
ccbRegisterOnFrameEvent
ccbUnregisterOnFrameEvent

Drawing

ccbDrawColoredRectangle
ccbDrawTextureRectangle
ccbDrawTextureRectangleWithAlpha

Collision

ccbGet3DPosFrom2DPos
ccbGet2DPosFrom3DPos
ccbGetCollisionPointOfWorldWithLine
ccbDoesLineCollideWithBoundingBoxOfSceneNode

Various

ccbEndProgram
ccbLoadTexture
ccbGetMousePosX
ccbGetMousePosY
ccbGetScreenWidth
ccbGetScreenHeight
ccbSetCloseOnEscapePressed
ccbSetCursorVisible
ccbSwitchToScene
ccbPlaySound
ccbStopSound
ccbGetCopperCubeVariable
ccbSetCopperCubeVariable
ccbReadFileContent
ccbWriteFileContent
ccbGetPlatform
ccbInvokeAction
ccbGetCurrentNode
ccbCleanMemory
ccbSwitchToFullscreen
ccbDoHTTPRequest
ccbCancelHTTPRequest
ccbCreateMaterial
ccbSetShaderConstant
ccbSetPhysicsVelocity
ccbUpdatePhysicsGeometry
ccbAICommand
ccbSteamSetAchievement
ccbSteamResetAchievements
ccbSaveScreenshot
ccbSaveTexture
ccbSwitchToCCBFile
print
system

Only in the editor

confirm 
alert 
prompt 
editorAddSceneNode 
editorFocusPosition
editorGetFileNameFromDialog
editorGetSelectedSceneNode
editorGetSelectedTexture
editorUpdateAllWindows
editorRegisterMenuEntry
editorSetSelectedSceneNode
editorImportStatic3DMesh
editorImportAnimated3DMesh

Mesh Editing

ccbGetSceneNodeMeshBufferCount
ccbRemoveMeshBuffer
ccbAddMeshBuffer
ccbGetMeshBufferVertexCount
ccbGetMeshBufferIndexCount
ccbAddMeshBufferIndex
ccbGetMeshBufferIndexValue
ccbSetMeshBufferIndexValue
ccbAddMeshBufferVertex
ccbGetMeshBufferVertexPosition
ccbSetMeshBufferVertexPosition
ccbGetMeshBufferVertexTextureCoord
ccbSetMeshBufferVertexTextureCoord
ccbGetMeshBufferVertexNormal
ccbSetMeshBufferVertexNormal
ccbGetMeshBufferVertexColor
ccbSetMeshBufferVertexColor
ccbUpdateSceneNodeBoundingBox

Other:

vector3d - a vector class
Standard Library
(basic functions for math, strings, arrays, regex etc)


ccbGetSceneNodeFromName("Name")

Parameters:
("Name") - String of the name of a scene node.

Searches the whole scene graph for a scene node with this name. Please note that the name is case sensitive. If it is found, it is returned, otherwise null is returned.

Returns: Returns the scene node based on the "Name".

Examples:

var s = ccbGetSceneNodeFromName("cubeMesh1"); if (s) print("found node.\n"); else print("not found the node.\n")

Result: Searches for a scene node with name 'cubeMesh1' and prints text if it is found or not.

ccbCloneSceneNode(Node)

Note: This function is not available in the editor.

Parameters:
(Node) - Scene node that needs to be cloned.

Creates a new scene node based on an existing scene node. All the behaviors and actions will also be applied to the cloned node. The parameter 'node' must be an existing scene node. You can get an existing scene node for example with ccbGetSceneNodeFromName().

Returns: The new cloned scene node.

Examples:

var sourceNode = ccbGetSceneNodeFromName("myNode"); var newscenenode = ccbCloneSceneNode(sourceNode);

Result: Above example will create a copy of an existing scene node with the name 'myNode'.

var name_increment = ccbGetCopperCubeVariable("name_increment"); var incremented_value = Number(name_increment + 1); ccbSetCopperCubeVariable("name_increment", incremented_value); var MainNode = ccbGetSceneNodeFromName("node_to_be_cloned"); var ClonedNode = ccbCloneSceneNode(MainNode); ccbSetSceneNodeProperty(ClonedNode, "Name", "new_name_for_clone"+ "" +incremented_value+ "" );

Result: Above example will create a clone of the existing node and will assign a new name to every node that is cloned with a number as suffix. In order to make the above script work, you need to set a CopperCube Variable "name_increment" with a value of "0".

ccbGetActiveCamera()

Note: This function is not available in the editor.

Returns: Returns the currently active camera node of the scene.

Examples:

var Camera = ccbGetActiveCamera(); var CameraName = ccbGetSceneNodeProperty(Camera,"Name"); print(CameraName)

Result: Above example will get the current active camera from the scene and will print the name of the camera in the debug console.

ccbSetActiveCamera(Node)

Note: This function is not available in the editor.

Parameters:
(Node) - Camera scene node that need to be set as an active camera.

Sets a camera node as currently active camera for the scene. The parameter 'node' must be an existing camera node. You can get an existing camera node for example with ccbGetSceneNodeFromName().

Examples:

var NewCamera = ccbGetSceneNodeFromName("Camera2"); ccbSetActiveCamera(NewCamera);

Result: Above example will get the camera with name "Camera2" from the scene and make it the current active camera for that scene.

ccbGetSceneNodeChildCount(Node)

Parameters:
(Node) - Scene node whose child nodes need to be counted.

It returns the number of total child nodes attached to a scene node. Parameter node must be an existing scene node.

Returns: Returns the amount of children of a scene node.

Examples:

var root = ccbGetRootSceneNode(); var count = ccbGetSceneNodeChildCount(root); print("Scene nodes in the top level of the scene graph:" + count);

Result: Above example will print the total number of scene nodes attached to the root scene node in your scene.

ccbGetChildSceneNode(ParentSceneNode, ChildIndex)

Parameters:
(ParentSceneNode) - Scene node with child scene nodes attached.
(ChildIndex) - An integer starting from 0 to maximum number of children the parent node has.

Returns the child scene node of a parent scene node. 'ChildIndex' must be >= 0 and less than the total childcount of that node that is less than the value return by ccbGetSceneNodeChildCount(). The parameter 'ParentSceneNode' must be an existing scene node. You can get an existing scene node for example with ccbGetSceneNodeFromName() and 'ChildIndex' must be an integer lower than the total child count of parent node

Returns: The child scene node at an index of specified parent scene node.

Examples:

var ParentNode = ccbGetSceneNodeFromName("myNode"); var Child = ccbGetChildSceneNode(parentNode, 0); var Childname = ccbGetSceneNodeProperty(Child, "Name"); print(Childname);

Result: Above example will get child at index 0 of a node with the name "myNode" and then print the name of the child node in the debug console.

var root = ccbGetRootSceneNode(); var count = ccbGetSceneNodeChildCount(root); //Using for loop to loop through all the childrens of root scene node for(var i=0; i<count; i++) { var child = ccbGetChildSceneNode(root, i); print("node:" + ccbGetSceneNodeProperty(child, "Name") + "\n"); }

Result: Above example will print name of all the children of the root scene node in the debug console.

ccbGetRootSceneNode()

Returns the root scene node. You cannot remove it, it always exist in a scene, but you can make changes to its attributes like :-
   ➱ Gravity                        ➱ Wind                   ➱ Realtime Shadows
   ➱ Fog                             ➱ FogColor             ➱ AmbientLight
   ➱ BackgroundColor
PostEffect properties are also supported :-
   ➱ Bloom                      ➱ Bloom_BlurIterations          ➱ Bloom_Treshold
   ➱ Black and White        ➱ Invert            ➱ Blur         ➱ Blur_Iterations
   ➱ Colorize                   ➱ Colorize_Color                 ➱ Vignette
   ➱ Vignette_Intensity      ➱ Vignette_RadiusA              ➱ Vignette_RadiusB
etc.

Returns: Returns the root scene node.

Examples:

var RootNode = ccbGetRootSceneNode(); var Fog = ccbGetSceneNodeProperty(RootNode,"Fog"); print(Fog);

Result: Above example will get the state of Fog in your scene and then print "true" or "false" in the debug console.

ccbGetSceneNodeProperty(Node, "PropertyName")

Parameters:
(Node) - Scene node whose property value should be returned.
("PropertyName") - String for the name of the property of a scene  node whose value should be returned, for example "Position".

Gets the property value of a scene node. The "PropertyName" is also the name displayed in the property window of the editor in the left column. Possible property names depend on the scene node type below is the list of properties available for different scene nodes. Please note that the name is case sensitive.

  • General properties for all type of nodes:
    ➱ "Position"    ➱ "Rotation"    ➱ "Scale"    ➱ "Visible"     ➱ "PositionAbs"      ➱"Type"

  • For Animated scene nodes:
    ➱ "Animation"    ➱ "Looping"    ➱ "FramesPerSecond"    ➱ "AnimationBlending"     ➱ "BlendTimeMs" 

  • For Camera nodes:
    ➱ "Target"     ➱ "UpVector"     ➱ "AspectRatio"     ➱"FieldOfView_Degrees"    ➱ "FarPlane"    ➱ "NearPlane"

  • For 2D overlay nodes:
    ➱ "Pos X (percent)"   ➱ "Pos Y (percent)"     ➱ "Width (percent)"      ➱ "Height (percent)"
    ➱ "Pos X (pixels)"      ➱ "Pos Y (pixels)"       ➱ "Width (pixels)"         ➱ "Height (pixels)"
    ➱ "Alpha"                   ➱ "Image"                   ➱"Background Color"   ➱"Draw Text"
    ➱ "Text"                      ➱ "Alignment"            ➱ "TextColor"                ➱ "Font"
    ➱ "Position Mode"

    Other properties for 2D overlays are also available like "OnHover Animate" and few other similar see the node properties in the editor. 

  • For light nodes:
    ➱ "Radius" (for point lights)     ➱ "Color"     ➱ "Direction" (for directional lights)

  • For the root scene node:  Check ccbGetRootSceneNode() for list of root node properties. 

Values return for the properties can be a Vector, Integer, Float, Boolean, or String depending on the property type.

Returns:
The value for a property of a scene node.

Examples:

var s = ccbGetSceneNodeFromName("cubeMesh1"); var position = ccbGetSceneNodeProperty(s, "Position"); print("The cube is at " + position);

Result: In above example if the scene contains a scene node with the name 'cubeMesh1', this will get the position vector of that node and prints something like "The cube is at (x, y, z)"  x, y and z here are the position of scene node on the respective axis.

var s = ccbGetSceneNodeFromName("overlay"); var font = ccbGetSceneNodeProperty(s,"Font"); print(font); // will give something like ("14; Swiss; Arial; Normal; Normal; false;"); // Format is based on this (Font Size; Font Family; Font Name; Font Style; Font Weight; Font underlined)

Result: Above example will print the font data of an existing 2D overlay whose name is "overlay" in your scene.

ccbSetSceneNodeProperty(Node, "PropertyName", Value)

Parameters:
(Node) - Scene node whose property needs to be changed.
("PropertyName") - String for the name of the property of a scene node that need to be set, for example "Position".
(Value) - Value can be a bool, integer, float, string, and vector.  Properties like  Color, Position, Rotation and Scale are generally vectors               and contains 3 values like (x,y,z) here x,y and z can be floats or integers.  

Sets the property value of a scene node. The "PropertyName" is also the name displayed in the property window of the editor in the left column. When setting a vector, you can use x,y,z parameters, or a vector3d object. For colors, you can use a single int or 3 RGB values like 255,128,0. Possible property names depend on the scene node type below is the list of properties available for different scene nodes. Please note that the name is case sensitive.

  • General properties for all type of nodes:
    ➱ "Position"    ➱ "Rotation"    ➱ "Scale"    ➱ "Visible"     ➱ "PositionAbs"      ➱"Type"

  • For Animated scene nodes:
    ➱ "Animation"    ➱ "Looping"    ➱ "FramesPerSecond"    ➱ "AnimationBlending"     ➱ "BlendTimeMs" 

  • For Camera nodes:
    ➱ "Target"     ➱ "UpVector"     ➱ "AspectRatio"     ➱"FieldOfView_Degrees"    ➱ "FarPlane"    ➱ "NearPlane"

  • For 2D overlay nodes:
    ➱ "Pos X (percent)"   ➱ "Pos Y (percent)"     ➱ "Width (percent)"      ➱ "Height (percent)"
    ➱ "Pos X (pixels)"      ➱ "Pos Y (pixels)"       ➱ "Width (pixels)"         ➱ "Height (pixels)"
    ➱ "Alpha"                   ➱ "Image"                   ➱"Background Color"   ➱"Draw Text"
    ➱ "Text"                      ➱ "Alignment"            ➱ "TextColor"                ➱ "Font"
    ➱ "Position Mode"

    Other properties for 2D overlays are also available like "OnHover Animate" and few other similar see the node properties in the editor. 

  • For light nodes:
    ➱ "Radius" (for point lights)     ➱ "Color"     ➱ "Direction" (for directional lights)

  • For the root scene node:  Check ccbGetRootSceneNode() for list of root node properties. 

Values return for the properties can be a Vector, Integer, Float, Boolean, or String depending on the property type.

Examples:

//get scenenode named "cubeMesh1" and store it in a variable called s.
var s = ccbGetSceneNodeFromName("cubeMesh1");
//use the variable s as a scenenode and change it's visibility to false to hide it.
ccbSetSceneNodeProperty(s, "Visible", false);

Result: In above example if the scene contains a scene node with the name 'cubeMesh1', then the above code will hide that  scene node by making it invisible. Remember hiding a node turns off any behavior that is attacked to it. It is better to add your code to other node or root node, if you want some of the behaviors to run even after the node is invisible.

// get the node with the name "cubeMesh1" and store it in a variable called s
var s = ccbGetSceneNodeFromName("cubeMesh1");

//Get the current Scale of the scenenode and store in a variable
var currentScale = ccbGetSceneNodeProperty(s,"Scale");

//multiply the X,Y and Z axis of the currentScale by 2 to double the size of the node ccbSetSceneNodeProperty(s,"Scale", currentScale.x*2, currentScale.y*2, currentScale.z*2);

Result: Above example will scale the object by 2, results in doubling the size of existing scenenode with the name "cubeMesh1".

ccbGetSceneNodeMaterialCount(Node)

Parameters:
(Node) - Scene node whose materials need to be counted.

It returns the number of total materials of a scene node. Parameter node must be an existing scene node.

Returns: Returns the amount of materials of a scene node.

Examples:

var s = ccbGetSceneNodeFromName("cubeMesh1"); var n = ccbGetSceneNodeMaterialCount(s); print("the scene node has " + n + " materials");

Result: Above example will print the amount of materials in a scene node named 'cubeMesh1'.

ccbRemoveSceneNode(Node)

Parameters:
(Node) - Scene node that needs to be removed.

It removes the scene node from the scene, deleting it. Doesn't work for the root scene node.

Examples:

var s = ccbGetSceneNodeFromName("cubeMesh1"); ccbRemoveSceneNode(s);

Result: Above example will delete a scene node with the name 'cubeMesh1' if it exists in the scene.

ccbSetSceneNodeParent(Node, ParentSceneNode)

Parameters:
(Node) - Scene node whose parent needs to be updated.
(ParentSceneNode) - Scene node that should be used as a parent for the Node.

Sets the parent scene node of node. If this node has already a parent, it will be removed from that parent. Note that by setting a new parent, position, rotation and scale of this node becomes relative to that of the new parent. By default "Root Node" is set as default parent for all the scene nodes.

Examples:

var s = ccbGetSceneNodeFromName("cubeMesh1"); var ParentNode = ccbGetSceneNodeFromName("myNode"); ccbSetSceneNodeParent(s, ParentNode); // Sets an existing scene node with name "myNode" as a new parent node for an existing node with name "cubeMesh1"

Result: Above example will set an existing scene node with name "myNode" as a new parent node for an existing scene node having name "cubeMesh1".

var root = ccbGetRootSceneNode(); var s = ccbGetSceneNodeFromName("cubeMesh1"); ccbSetSceneNodeParent(s, root);

Result: Above example will make an existing scene node with name "cubeMesh1" a children of  the  "Root Scene Node".

ccbSetSceneNodePositionWithoutCollision(Node, X, Y, Z)

Parameters:
(Node) - Scene node whose position need to be changed.
(X) - New Position for the X-Coordinate.
(Y) - New Position for the Y-Coordinate.
(Z) - New Position for the Z-Coordinate.

Sets a new position of a scene node, even if the scene node has a 'collide when moved' behavior attached to it. So it it possible to move such a scene node through walls or other obstacles. Note that you have to ensure that the new position of the scene node is not inside a wall, otherwise the node might get stuck.

Examples:

var s = ccbGetSceneNodeFromName("cubeMesh1"); ccbSetSceneNodePositionWithoutCollision(s, -20, 10, -40);

Result: Above example will make an existing scene node with name "cubeMesh1"  change its position to (-20,10,-40) , independent of its collision behavior.

ccbRegisterKeyDownEvent("Function")

Note: This function is not available in the editor, and only in the Windows and Mac OS X app target. For getting key events, use the behavior functions "behaviorName.prototype.onKeyEvent()".

Parameters:
(Function) - Name of the function that needs to be registered as KeyDownEvent. Name must be in string format otherwise you will get an error.

Registers a function for receiving a key down event. The function registered must take one parameter which will be the key code.

Examples:

function keyPressedDown(keyCode) { print("A key was pressed down:" + keyCode); } ccbRegisterKeyDownEvent("keyPressedDown");

Result: Above example will print which key was pressed when it is pressed.

ccbRegisterKeyUpEvent("Function")

Note: This function is not available in the editor, and only in the Windows and Mac OS X app target. For getting key events, use the behavior functions "behaviorName.prototype.onKeyEvent()".

Parameters:
("Function") - Name of the function that needs to be registered as KeyUpEvent. Name must be in string format otherwise you will get an error.

Registers a function for receiving a key up event that is when a key is released. The function registered must take one parameter which will be the key code.

Examples:

function keyLeftUp(keyCode) { print("A key was left up:" + keyCode); } ccbRegisterKeyUpEvent("keyLeftUp");

Result: Above example will print which key was left up when it is released.

ccbRegisterMouseDownEvent("Function")

Note: This function is not available in the editor, and only in the Windows and Mac OS X app target. For getting mouse events, use the behavior functions "behaviorName.prototype.onMouseEvent()".

Parameters:
("Function") - Name of the function that needs to be registered as MouseDownEvent. Name must be in string format otherwise you will get an error.

Registers a function for receiving a mouse down event that is when a mouse button is pressed. The function registered must take one parameter which will be the mouse button pressed (0 for left button, 1 for right button, 2 for middle button).

Examples:

function mousePressedDown(button) { print("A mouse button was presssed down:" + button); } ccbRegisterMouseDownEvent("mousePressedDown");

Result: Above example will prints which mouse button was pressed when it is pressed.

ccbRegisterMouseUpEvent("Function")

Note: This function is not available in the editor, and only in the Windows and Mac OS X app target. For getting mouse events, use the behavior functions "behaviorName.prototype.onMouseEvent()".

Parameters:
("Function") - Name of the function that needs to be registered as MouseUpEvent. Name must be in string format otherwise you will get an error.

Registers a function for receiving a mouse up event that is when a mouse button is released. The function registered must take one parameter which will be the mouse button released (0 for left button, 1 for right button, 2 for middle button).

Examples:

function mouseLeftUp(button) { print("A mouse button was left up:" + button); } ccbRegisterMouseUpEvent("mouseLeftUp");

Result: Above example will prints which mouse button was left up when it is released.

ccbRegisterOnFrameEvent(Function)
ccbUnregisterOnFrameEvent(Function)

Note: These functions are not available in the editor.

Parameters:
(Function) - Name of the function that needs to be register or unregister.

ccbRegisterOnFrameEvent(Function) registers a function for receiving an 'on frame' event, an event which is called every frame the screen is drawn. The function registered must take no parameters. Inside this function, it is possible to draw own, custom things like user interfaces and other stuff.
After you no longer need events, you can call ccbUnregisterOnFrameEvent(Function) to unregister your function.

Examples:

function onFrameDrawing() { // draw a red, transparent rectangle at the position of the mouse var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); ccbDrawColoredRectangle(0x77ff0000, mouseX-10, mouseY-10, mouseX+10, mouseY+10); } ccbRegisterOnFrameEvent(onFrameDrawing);

Result: Above example will draw a red rectangle at the position of the mouse cursor (or at the center if the mouse cursor is controlling a FPS style camera). Check the code below to stop drawing the rectangle.

// To unRegister the function created in above example ccbUnregisterOnFrameEvent(onFrameDrawing);

Result: Above code will unregister the 'on frame' event that we created in the first example that draws a red rectangle at mouse position.

ccbDrawColoredRectangle(Color, X1, Y1, X2, Y2)

Note: This function is not available in the editor. This function can only be used inside an "on frame" event function which must have been registered with ccbRegisterOnFrameEvent().

Parameters:
(Color) - Color in (0xaarrggbb) format for the rectangle.
(X1) - 2D position on screen for X-Coordinate where the rectangle should start drawing from the point.
(Y1) - 2D position on screen for Y-Coordinate where the rectangle should start drawing from the point.
(X2) - 2D position on screen for X-Coordinate where the rectangle should end drawing to the point.
(Y2) - 2D position on screen for Y-Coordinate where the rectangle should end drawing to point.

Draws a colored rectangle. This function can only be used inside an "on frame" event function which must have been registered with ccbRegisterOnFrameEvent.

The color is a 32 bit value with alpha, red, green and blue components (0xaarrggbb, like the color values known from HTML but with an alpha channel value added in front, for the transparency). 0x770000ff is for example a transparent blue, to draw opaque rectangles, see the code provided for color conversion checkout the page for Javascript Color conversion.

Examples:

function onFrameDrawing() { // draw a blue, transparent rectangle at the center of the screen var screenX = ccbGetScreenWidth()/2; //Divide by 2 to get the center of the screen var screenY = ccbGetScreenHeight()/2; //Divide by 2 to get the center of the screen ccbDrawColoredRectangle(0x770000ff, screenX-10, screenY-10, screenX+10, screenY+10); } ccbRegisterOnFrameEvent(onFrameDrawing);

Result: Above example will draw a blue transparent rectangle at the center of the screen.

ccbDrawTextureRectangle("File", X1, Y1, X2, Y2)

Note: This function is not available in the editor. This function can only be used inside an "on frame" event function which must have been registered with ccbRegisterOnFrameEvent().

Parameters:
("File") - Path to the texture file that needs to be drawn.
(X1) - 2D position on screen for X-Coordinate where the rectangle should start drawing from the point.
(Y1) - 2D position on screen for Y-Coordinate where the rectangle should start drawing from the point.
(X2) - 2D position on screen for X-Coordinate where the rectangle should end drawing to the point.
(Y2) - 2D position on screen for Y-Coordinate where the rectangle should end drawing to point.

Draws a textured rectangle with alpha channel. This function can only be used inside an "on frame" event function which must have been registered with ccbRegisterOnFrameEvent.

This function will ignore the alpha channel of the texture. Use ccbDrawTextureRectangleWithAlpha if you want the alpha channel to be taken into account as well.

Examples:

function onFrameDrawing() { // draw a textured rectangle at the top left of the screen ccbDrawTextureRectangle("images\\image.png", 0, 0, 100, 100); //Change the value 100 to change the size of the texture } ccbRegisterOnFrameEvent(onFrameDrawing);

Result: Above example will draw an image to the top left of the screen, the texture "image.png" needs to be exist in a directory "images" in the same folder as of your game. 

ccbDrawTextureRectangleWithAlpha("File", X1, Y1, X2, Y2)

Note: This function is not available in the editor. This function can only be used inside an "on frame" event function which must have been registered with ccbRegisterOnFrameEvent().

Parameters:
("File") - Path to the texture file that needs to be drawn.
(X1) - 2D position on screen for X-Coordinate where the rectangle should start drawing from the point.
(Y1) - 2D position on screen for Y-Coordinate where the rectangle should start drawing from the point.
(X2) - 2D position on screen for X-Coordinate where the rectangle should end drawing to the point.
(Y2) - 2D position on screen for Y-Coordinate where the rectangle should end drawing to point.

Draws a textured rectangle with alpha channel. This function can only be used inside an "on frame" event function which must have been registered with ccbRegisterOnFrameEvent.

This function will take the alpha channel of the texture into account, use ccbDrawTextureRectangle to draw texture that does not have an alpha channel.

Examples:

function onFrameDrawing() { // draw a custom mouse cursor using a cursor image as texture at the position of mouse var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); ccbDrawTextureRectangleWithAlpha("cursor.png", mouseX-20, mouseY-20, mouseX+20, mouseY+20); //Change the value 20 above to adjust the size of cursor texture } ccbRegisterOnFrameEvent(onFrameDrawing); ccbSetCursorVisible(false); //Hide the default cursor

Result: Above example will hide the default cursor and draws a custom image "cursor.png" with transparency at the position of mouse cursor. When you don't specify the full path of the texture, CopperCube checks the file in the same directory as of your game, so make sure you are having the file in right place. 

ccbGet3DPosFrom2DPos(X, Y)

Parameters:
(X) - 2D position on screen for X-Coordinate.
(Y) - 2D position on screen for Y-Coordinate.

Returns the 3d position of a 2d position on the screen. Note: A 2d position on the screen does not represent one single 3d point, but actually a 3d line. So in order to get this line, use the 3d point returned by this function and the position of the current camera to form this line.

Returns: Returns the 3d position from a 2d position on the screen.

Examples:

var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); var s = ccbGetSceneNodeFromName("cubeMesh1"); var pos3d = ccbGet3DPosFrom2DPos(mouseX, mouseY); // use mouse position for 3D position ccbSetSceneNodeProperty(s, "Position", pos3d);

Result: Above example will sets the position of an existing scene node with the name 'cubeMesh1' to the 3d position behind the mouse cursor.

ccbGet2DPosFrom3DPos(X, Y, Z)

Parameters:
(X) - 3D position for X-Coordinate.
(Y) - 3D position for Y-Coordinate.
(Z) - 3D position for Z-Coordinate.

Returns the 2D position from a 3D position or nothing if the position would not be on the screen (for example behind the camera). The position returned will be camera view dependent, so won't give a fixed result. 

Returns: Returns the 2D position from a 3D position on the screen.

Examples:

var pos = ccbGet2DPosFrom3DPos(20, 30, 30); print("Position on screen: " + pos); //prints the position of X and Y as 2D position the Z position will always be zero. //The returned position is camera dependent so won't give you a fixed result

Result: Above example will prints the position of a 3d coordinate (20,30,30) in 2D.

ccbGetCollisionPointOfWorldWithLine(StartX, StartY, StartZ, EndX, EndY, EndZ)

Parameters:
(StartX) - Starting position of the line on X-Coordinate.
(StartY) - Starting position of the line on Y-Coordinate.
(StartZ) - Starting position of the line on Z-Coordinate.
(EndX) - Ending position of the line on X-Coordinate.
(EndY) - Ending position of the line on Y-Coordinate.
(EndZ) - Ending position of the line on X-Coordinate.

Returns the collision point with a line and the world which means if casted line collides with anything in the world it will return the point or position where the collision occurs. Returns null if there is no collision.

Returns: Returns the collision point with the world.

Examples:

function onFrameDrawing()
{   var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); // test collision by drawing a line from camera to the mouse position var startPoint = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position"); // get camera position var endPoint = ccbGet3DPosFrom2DPos(mouseX, mouseY); // Convert mouse position into 3d position
 var collisionPoint = ccbGetCollisionPointOfWorldWithLine(startPoint.x, startPoint.y,

startPoint.z, endPoint.x, endPoint.y, endPoint.z);

   if (collisionPoint != null) //checks if Collision happens or not

{
print("The casted line collides with something at position :- " + collisionPoint);
}

  else { print("The casted line doesn't collides with anything");}

}

ccbRegisterOnFrameEvent(onFrameDrawing);

//Prints the collision point if collision occurs of a line casted from camera towards the mouse position.

Result: Above example will print the collision point if a the line casted from camera towards the mouse position collides with anything in the scene.

ccbDoesLineCollideWithBoundingBoxOfSceneNode(Node, StartX, StartY, StartZ, EndX, EndY, EndZ)

Parameters:
(Node) - Node whose bounding box needs to be checked for collision.
(StartX) - Starting position of the line on X-Coordinate.
(StartY) - Starting position of the line on Y-Coordinate.
(StartZ) - Starting position of the line on Z-Coordinate.
(EndX) - Ending position of the line on X-Coordinate.
(EndY) - Ending position of the line on Y-Coordinate.
(EndZ) - Ending position of the line on X-Coordinate.

Returns if the bounding box of the given scene node collides with the line between two given 3D points.

Returns: Returns true or false by checking collision between a line and bounding box of a scene node.

Examples:

function onFrameDrawing() { var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); // test collision of the line with the bounding box of "cubeMesh1" var cube = ccbGetSceneNodeFromName("cubeMesh1"); var endPoint = ccbGet3DPosFrom2DPos(mouseX, mouseY); var startPoint = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position"); if (ccbDoesLineCollideWithBoundingBoxOfSceneNode(cube, startPoint.x, startPoint.y, startPoint.z, endPoint.x, endPoint.y, endPoint.z)) { ccbDrawColoredRectangle(0x77ff0000, mouseX-10, mouseY-10, mouseX+10, mouseY+10); } else { ccbDrawColoredRectangle(0x770000ff, mouseX-10, mouseY-10, mouseX+10, mouseY+10);} } ccbRegisterOnFrameEvent(onFrameDrawing);

Result: Above example will draw a red rectangle at the position of the mouse cursor (or the center of the screen if controlled by a FPS style camera controller) if the mouse cursor is over an existing scene node named 'cubeMesh1', and draws a blue rectangle if not.

ccbEndProgram()

Note: This function is not available in the editor.

Ends the application. On Flash and WebGL, this closes the window (if it was opened before as popup by a script).

Examples:

ccbEndProgram(); //Close the game in Windows or the browser tab if using in a webGL game.

Result: Above example will close the game window.

ccbGetMousePosX()

Note: This function is not available in the editor.

Returns the current X position of the mouse cursor from screen in pixels.

Returns: Returns the current X position of the mouse cursor in pixels.

Examples:

var mouseX = ccbGetMousePosX(); print(mouseX); // Print the X position of mouse in debug console

Result: Above example will print the mouse position for the X-Coordinate of screen in debug panel.

ccbGetMousePosY()

Note: This function is not available in the editor.

Returns the current Y position of the mouse cursor from screen in pixels.

Returns: Returns the current Y position of the mouse cursor in pixels.

Examples:

function onFrameDrawing() { var mouseY = ccbGetMousePosY(); var overlay = ccbGetSceneNodeFromName("2D Overlay1"); ccbSetSceneNodeProperty(overlay,"Draw Text",true); //Enable Text Drawing for overlay ccbSetSceneNodeProperty(overlay,"Text", "Y:- " + mouseY); //Change the text of overlay } ccbRegisterOnFrameEvent(onFrameDrawing);

Result: Above example will enable and change the Text of an existing 2D overlay with name "2D Overaly1" with the Y-Position of mouse cursor in pixels. It updates the text on every frame.

ccbSetMousePos(X, Y)

Note: This function is not available in the editor. This function is only available in the Windows .exe and macOS .app target.

Parameters:
(X) - Position in pixels to set on the X-axis for mouse cursor.
(Y) - Position in pixels to set on the Y-axis for mouse cursor.

Sets cursor position to a new position on the game screen

Examples:

var screenY = ccbGetScreenHeight();
var screenX = ccbGetScreenWidth();
ccbSetMousePos(screenX/4,screenY/4);

//put mouse cursor in the 1/4th part of the screen

Result: Above example will set the mouse cursor position to the 1/4th part of the screen, that is to the top left part of the game screen.

ccbGetScreenWidth()

Note: This function is not available in the editor.

Returns the current width of the screen in pixels, that is the width of the screen for X-Coordinate.

Returns: Returns the current width of the game screen in pixels.

Examples:

var screenX = ccbGetGetScreenWidth(); print(screenX); // Print the width of the game screen in debug console

Result: Above example will print the Width of screen in debug panel.

ccbGetScreenHeight()

Note: This function is not available in the editor.

Returns the current height of the screen in pixels, that is the width of the screen for Y-Coordinate.

Returns: Returns the current height of the game screen in pixels.

Examples:

var screenY = ccbGetGetScreenHeight(); print(screenY); // Print the Height of the game screen in debug console

Result: Above example will print the Height of screen in debug panel.

ccbSetCursorVisible(true/false)

Note: This function may not do anything depending on the target it runs on (web apps for example have no access to the cursor). This function is not available in the editor.

Parameters:
(true/false) - A boolean either true or false to set the visibility of cursor.

Sets if the mouse cursor is visible or not. Call ccbSetCursorVisible(false) to make it invisible, call ccbSetCursorVisible(true) to make visible again.

Examples:

ccbSetCursorVisible(false);
//Hide the mouse cursor if it is visible already

Result: Above example will hide the mouse cursor in the game screen if it is visible.

ccbSwitchToScene("SceneName")

Note: This function is not available in the editor.

Parameters:
("SceneName") - Name of the scene to which we want to switch.

Switch to the scene with the specified name. Note: The name is case sensitive.

Examples:

ccbSwitchToScene("level 2"); //switch to the scene with name "Level 2".

Result: Above example will switch the current scene to another existing scene with the name "Level  2".

ccbSetCopperCubeVariable("VariabaleName", VariableValue)

Note: This function is not available in the editor.

Parameters:
("VariableName") - Name that you want for the CopperCube variable. Variable names are case sensitive.
(VariableValue) - Value that you want to assign to the CopperCube variable. It can be string, numbers , booleans etc.

Will set a CopperCube variable to a certain value. CopperCube variables can also be set and changed via the Variable Actions inside editor.

Examples:

ccbSetCopperCubeVariable("#system.soundvolume",50);


//"#sytem.soundvolume" is inbuilt CopperCube variable for sound volume

Result: Above example will change the master volume of your game to 50.

ccbSetCopperCubeVariable("Website", "vazahat.github.io");

Result: Above example will create and set a CopperCube variable with name "website" having a value "vazahat.github.io".

ccbGetCopperCubeVariable("VariabaleName")

Note: This function is not available in the editor.

Parameters:
("VariableName") - Name of the CopperCube variable whose value you want to get. Variable names are case sensitive.

Returns the value of a CopperCube variable if it exists. Returns 0 or false if variable doesn't exist.

Returns: Returns the value of a CopperCube variable if it exists.

Examples:

var websiteName = ccbGetCopperCubeVariable("Website");

print(websiteName);

Result: Above example will print the value of the CopperCube variable "Website", and if the variable don't exist , it will print 0 in the debug console. If you initially set the variable using the example in ccbSetCopperCubeVariable command then it will print the name of this website as "vazahat.github.io".

ccbWriteFileContent("FileName", "Content")

Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system).

Parameters:
("FileName") - Name of the file to save with the content. File path can be specified in it as well.
("Content") - Text content that needs to be save in the file.

Creates a text file on the local storage with the text string provided as content.

Examples:

var text = "Neophyte is a website that deal with Coppercube related stuff"; ccbWriteFileContent("Example.txt", text) ; //creates a text file

Result: Above example will create a text file with the name "Example.txt" in the same directory as of your project.

ccbReadFileContent("FileName")

Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system).

Parameters:
("FileName") - Name of the file whose content needs to read and returned as string.

Reads the content of a text file and return it as string.

Returns: Content of the file as string.

Examples:

var text = ccbReadFileContent("assets\\dialogue.txt"); print(text);

Result: Above example will reads the text from a file named "dialogue.txt" located in a folder name "assets" in the project directory
            and print it in the debug console. 

ccbFileExist("FileName")

Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system).

Parameters:
("FileName") - Name of the file that's need to be checked. Path can be included as well. 

Checks and return true or false based on the existence of the file in a directory.

Returns: True or False based on the file existence.

Examples:

var FileExistence = ccbFileExist("Example.txt"); print(FileExistence);// Prints true or false

Result: Above example will check if a file named "example.txt" exist in the directory of the project or not , if it is then print true else it will print false in the debug console.

About

Neophyte is a website developed to provide tutorials, assets and source files of CopperCube projects.

Join Us