Cocos Creator API

1.3.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Graphics

: cc

lineWidth Number

Current line width.

lineJoin Graphics.LineJoin

lineJoin determines how two connecting segments (of lines, arcs or curves) with non-zero lengths in a shape are joined together.

lineCap Graphics.LineCap

lineCap determines how the end points of every line are drawn.

strokeColor Color

stroke color

fillColor Color

fill color

miterLimit Number

Sets the miter limit ratio

_sgNode _ccsg.Node private

Reference to the instance of _ccsg.Node If it is possible to return null from your overloaded _createSgNode, then you should always check for null before using this property and reimplement __preload.

node Node

The node this component is attached to. A component is always attached to a node.

:

cc.log(comp.node);

uuid String readOnly

The uuid for editor.

:

cc.log(comp.uuid);

_enabled Boolean private

enabled Boolean

indicates whether this component is enabled or not.

:

comp.enabled = true;
cc.log(comp.enabled);

enabledInHierarchy Boolean readOnly

indicates whether this component is enabled and its node is also active in the hierarchy.

:

cc.log(comp.enabledInHierarchy);

_isOnLoadCalled Boolean readOnly

TODO

:

cc.log(_isOnLoadCalled);

__eventTargets Array private

Register all related EventTargets, all event callbacks will be removed in _onPreDestroy

_name String private

_objFlags Number private

name String

The name of the object.

:

obj.name = "New Obj";

isValid Boolean readOnly

Indicates whether the object is not yet destroyed.

:

cc.log(obj.isValid);

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

moveTo
(
  • [x ]
  • [y ]
)

Move path start point to (x,y).

x optional Number

The x axis of the coordinate for the end point.

y optional Number

The y axis of the coordinate for the end point.

lineTo
(
  • [x ]
  • [y ]
)

Adds a straight line to the path

x optional Number

The x axis of the coordinate for the end point.

y optional Number

The y axis of the coordinate for the end point.

bezierCurveTo
(
  • [c1x ]
  • [c1y ]
  • [c2x ]
  • [c2y ]
  • [x ]
  • [y ]
)

Adds a cubic Bézier curve to the path

c1x optional Number

The x axis of the coordinate for the first control point.

c1y optional Number

The y axis of the coordinate for first control point.

c2x optional Number

The x axis of the coordinate for the second control point.

c2y optional Number

The y axis of the coordinate for the second control point.

x optional Number

The x axis of the coordinate for the end point.

y optional Number

The y axis of the coordinate for the end point.

quadraticCurveTo
(
  • [cx ]
  • [cy ]
  • [x ]
  • [y ]
)

Adds a quadratic Bézier curve to the path

cx optional Number

The x axis of the coordinate for the control point.

cy optional Number

The y axis of the coordinate for the control point.

x optional Number

The x axis of the coordinate for the end point.

y optional Number

The y axis of the coordinate for the end point.

arc
(
  • [cx ]
  • [cy ]
  • [r ]
  • [startAngle ]
  • [endAngle ]
  • [counterclockwise ]
)

Adds an arc to the path which is centered at (cx, cy) position with radius r starting at startAngle and ending at endAngle going in the given direction by counterclockwise (defaulting to false).

cx optional Number

The x axis of the coordinate for the center point.

cy optional Number

The y axis of the coordinate for the center point.

r optional Number

The arc's radius.

startAngle optional Number

The angle at which the arc starts, measured clockwise from the positive x axis and expressed in radians.

endAngle optional Number

The angle at which the arc ends, measured clockwise from the positive x axis and expressed in radians.

counterclockwise optional Number

An optional Boolean which, if true, causes the arc to be drawn counter-clockwise between the two angles. By default it is drawn clockwise.

ellipse
(
  • [cx ]
  • [cy ]
  • [rx ]
  • [ry ]
)

Adds an ellipse to the path.

cx optional Number

The x axis of the coordinate for the center point.

cy optional Number

The y axis of the coordinate for the center point.

rx optional Number

The ellipse's x-axis radius.

ry optional Number

The ellipse's y-axis radius.

circle
(
  • [cx ]
  • [cy ]
  • [r ]
)

Adds an circle to the path.

cx optional Number

The x axis of the coordinate for the center point.

cy optional Number

The y axis of the coordinate for the center point.

r optional Number

The circle's radius.

rect
(
  • [x ]
  • [y ]
  • [w ]
  • [h ]
)

Adds an rectangle to the path.

x optional Number

The x axis of the coordinate for the rectangle starting point.

y optional Number

The y axis of the coordinate for the rectangle starting point.

w optional Number

The rectangle's width.

h optional Number

The rectangle's height.

roundRect
(
  • [x ]
  • [y ]
  • [w ]
  • [h ]
  • [r ]
)

Adds an round corner rectangle to the path.

x optional Number

The x axis of the coordinate for the rectangle starting point.

y optional Number

The y axis of the coordinate for the rectangle starting point.

w optional Number

The rectangles width.

h optional Number

The rectangle's height.

r optional Number

The radius of the rectangle.

fillRect
(
  • [x ]
  • [y ]
  • [w ]
  • [h ]
)

Draws a filled rectangle.

x optional Number

The x axis of the coordinate for the rectangle starting point.

y optional Number

The y axis of the coordinate for the rectangle starting point.

w optional Number

The rectangle's width.

h optional Number

The rectangle's height.

clear ( )

Erasing any previously drawn content.

close ( )

Causes the point of the pen to move back to the start of the current path. It tries to add a straight line from the current point to the start.

stroke ( )

Strokes the current or given path with the current stroke style.

stroke ( )

Fills the current or given path with the current fill style.

_createSgNode ( ) _ccsg.Node private

Create and returns your new scene graph node (SGNode) to add to scene graph. You should call the setContentSize of the SGNode if its size should be the same with the node's.

:

: _ccsg.Node

_initSgNode ( ) private

_removeSgNode ( ) private

update ( )

Update is called every frame, if the Component is enabled.

lateUpdate ( )

LateUpdate is called every frame, if the Component is enabled.

__preload ( ) private

__preload is called before every onLoad. It is used to initialize the builtin components internally, to avoid checking whether onLoad is called before every public method calls. This method should be removed if script priority is supported.

onLoad ( )

When attaching to an active node or its node first activated.

start ( )

Called before all scripts' update if the Component is enabled the first time.

onEnable ( )

Called when this component becomes enabled and its node is active.

onDisable ( )

Called when this component becomes disabled or its node becomes inactive.

onDestroy ( )

Called when this component will be destroyed.

onFocusInEditor ( )

onLostFocusInEditor ( )

addComponent
(
  • typeOrTypename
)
Component

Adds a component class to the node. You can also add component to node by passing in the name of the script.

typeOrTypename Function | String

the constructor or the class name of the component to add

:

: Component

the newly added component

:

var sprite = node.addComponent(cc.Sprite);
var test = node.addComponent("Test");

getComponent
(
  • typeOrClassName
)
Component

Returns the component of supplied type if the node has one attached, null if it doesn't.
You can also get component in the node by passing in the name of the script.

typeOrClassName Function | String

:

:

// get sprite component.
var sprite = node.getComponent(cc.Sprite);
// get custom test calss.
var test = node.getComponent("Test");

getComponents
(
  • typeOrClassName
)
Component[]

Returns all components of supplied Type in the node.

typeOrClassName Function | String

:

var sprites = node.getComponents(cc.Sprite);
var tests = node.getComponents("Test");

getComponentInChildren
(
  • typeOrClassName
)
Component

Returns the component of supplied type in any of its children using depth first search.

typeOrClassName Function | String

:

:

var sprite = node.getComponentInChildren(cc.Sprite);
var Test = node.getComponentInChildren("Test");

getComponentsInChildren
(
  • typeOrClassName
)
Component[]

Returns the components of supplied type in self or any of its children using depth first search.

typeOrClassName Function | String

:

var sprites = node.getComponentsInChildren(cc.Sprite);
var tests = node.getComponentsInChildren("Test");

_getLocalBounds
(
  • out_rect
)

If the component's bounding box is different from the node's, you can implement this method to supply a custom axis aligned bounding box (AABB), so the editor's scene view can perform hit test properly.

out_rect