kick.scene.GameObject Class
Game objects. (Always attached to a given scene). This constructor should not be called directly - Scene.createGameObject() should be used instead.
Constructor
kick.scene.GameObject
-
scene
-
config
Parameters:
-
scene
kick.scene.Scene -
config
Objectconfiguration for gameObject (components will not be initialized)
Item Index
Methods
Events
Methods
addComponent
-
component
Add the component to a gameObject and set the gameObject field on the component
Parameters:
-
component
kick.scene.Component
destroy
()
Destroys game object after next frame. Removes all components instantly. This method will call destroyGameObject on the associated scene.
getComponent
-
index
Get component by index.
Parameters:
-
index
Number
Returns:
getComponentOfType
-
type
Get the first component of a specified type. Internally uses instanceof.
Example usage:
Parameters:
-
type
Objectthe constructor of the wanted component
Returns:
component of specified type or null
Example:
var meshRenderer = someGameObject.getComponentOfType(kick.scene.MeshRenderer);
var material = meshRenderer.material;
getComponentsOfType
-
type
Get all component of a specified type. Internally uses instanceof.
Example usage:
Parameters:
-
type
Objectthe constructor of the wanted component
Returns:
arrays of components of specified type
Example:
var meshRenderer = someGameObject.getComponentsOfType(kick.scene.MeshRenderer);
if (meshRenderer.length > 0){
material = meshRenderer[0].material;
}
getComponentsWithMethod
-
methodName
Get the first component with a specific method.
Example usage:
Parameters:
-
methodName
Stringof the method
Returns:
component of with a method with a specific method name
Example:
var renderer = someGameObject.getComponentsWithMethod("render");
getComponentsWithMethod
-
methodName
Get all components with a specific method.
Example usage:
Parameters:
-
methodName
Objectthe constructor of the wanted component
Returns:
arrays of components of specified type
Example:
var renderers = someGameObject.getComponentsWithMethod("render");
for (var i = 0; i < renderers.length; i++){
renderers[i].render(obj);
}
notifyComponentUpdated
-
component
Invoked when component updated (such as material change).
Parameters:
-
component
kick.scene.Component
removeComponent
-
component
Remove the component from a gameObject and clear the gameObject field on the component
Parameters:
-
component
kick.scene.Component
toJSON
()
Returns:
JSON object
Properties
destroyed
Boolean
layer
Number
Layer bit flag. The default value is 1. The layer should have a value of 2^n
name
String
numberOfComponents
Number
Number of components
uid
Number
Unique id - identifies a game object (within a scene).
Events
componentAdded
Fired when a new component is added to gameObject
Event Payload:
-
component
kick.scene.Component
componentRemoved
Fired when a new component is removed from gameObject
Event Payload:
-
component
kick.scene.Component