cmkit
Version:
common web developer tool box.
1,835 lines (1,705 loc) • 1.19 MB
TypeScript
/** !#en
The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace.
!#zh
Cocos 引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。 */
declare namespace cc {
/** The current version of Cocos2d being used.<br/>
Please DO NOT remove this String, it is an important flag for bug tracking.<br/>
If you post a bug to forum, please attach this flag. */
var ENGINE_VERSION: string;
/**
!#en
Creates the speed action which changes the speed of an action, making it take longer (speed > 1)
or less (speed < 1) time. <br/>
Useful to simulate 'slow motion' or 'fast forward' effect.
!#zh 修改目标动作的速率。
@param action action
@param speed speed
@example
```js
// change the target action speed;
var action = cc.scaleTo(0.2, 1, 0.6);
var newAction = cc.speed(action, 0.5);
```
*/
function speed(action: ActionInterval, speed: number): Action;
/**
!#en Create a follow action which makes its target follows another node.
!#zh 追踪目标节点的位置。
@param followedNode followedNode
@param rect rect
@example
```js
// example
// creates the action with a set boundary
var followAction = cc.follow(targetNode, cc.rect(0, 0, screenWidth * 2 - 100, screenHeight));
node.runAction(followAction);
// creates the action with no boundary set
var followAction = cc.follow(targetNode);
node.runAction(followAction);
```
*/
function follow(followedNode: Node, rect: Rect): Action;
/**
Points setter
@param points points
*/
function setPoints(points: any[]): void;
/**
!#en Creates an action with a Cardinal Spline array of points and tension.
!#zh 按基数样条曲线轨迹移动到目标位置。
@param duration duration
@param points array of control points
@param tension tension
@example
```js
//create a cc.CardinalSplineTo
var action1 = cc.cardinalSplineTo(3, array, 0);
```
*/
function cardinalSplineTo(duration: number, points: any[], tension: number): ActionInterval;
/**
update position of target
@param newPos newPos
*/
function updatePosition(newPos: Vec2): void;
/**
!#en Creates an action with a Cardinal Spline array of points and tension.
!#zh 按基数样条曲线轨迹移动指定的距离。
@param duration duration
@param points points
@param tension tension
*/
function cardinalSplineBy(duration: number, points: any[], tension: number): ActionInterval;
/**
!#en Creates an action with a Cardinal Spline array of points and tension.
!#zh 按 Catmull Rom 样条曲线轨迹移动到目标位置。
@param dt dt
@param points points
@example
```js
var action1 = cc.catmullRomTo(3, array);
```
*/
function catmullRomTo(dt: number, points: any[]): ActionInterval;
/**
!#en Creates an action with a Cardinal Spline array of points and tension.
!#zh 按 Catmull Rom 样条曲线轨迹移动指定的距离。
@param dt dt
@param points points
@example
```js
var action1 = cc.catmullRomBy(3, array);
```
*/
function catmullRomBy(dt: number, points: any[]): ActionInterval;
/**
!#en
Creates the action easing object with the rate parameter. <br />
From slow to fast.
!#zh 创建 easeIn 缓动对象,由慢到快。
@param rate rate
@example
```js
action.easing(cc.easeIn(3.0));
```
*/
function easeIn(rate: number): any;
/**
!#en
Creates the action easing object with the rate parameter. <br />
From fast to slow.
!#zh 创建 easeOut 缓动对象,由快到慢。
@param rate rate
@example
```js
action.easing(cc.easeOut(3.0));
```
*/
function easeOut(rate: number): any;
/**
!#en
Creates the action easing object with the rate parameter. <br />
Slow to fast then to slow.
!#zh 创建 easeInOut 缓动对象,慢到快,然后慢。
@param rate rate
@example
```js
action.easing(cc.easeInOut(3.0));
```
*/
function easeInOut(rate: number): any;
/**
!#en
Creates the action easing object with the rate parameter. <br />
Reference easeInExpo: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeExponentialIn 缓动对象。<br />
EaseExponentialIn 是按指数函数缓动进入的动作。<br />
参考 easeInExpo:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
action.easing(cc.easeExponentialIn());
```
*/
function easeExponentialIn(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeOutExpo: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeExponentialOut 缓动对象。<br />
EaseExponentialOut 是按指数函数缓动退出的动作。<br />
参考 easeOutExpo:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
action.easing(cc.easeExponentialOut());
```
*/
function easeExponentialOut(): any;
/**
!#en
Creates an EaseExponentialInOut action easing object. <br />
Reference easeInOutExpo: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeExponentialInOut 缓动对象。<br />
EaseExponentialInOut 是按指数函数缓动进入并退出的动作。<br />
参考 easeInOutExpo:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
action.easing(cc.easeExponentialInOut());
```
*/
function easeExponentialInOut(): any;
/**
!#en
Creates an EaseSineIn action. <br />
Reference easeInSine: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 EaseSineIn 缓动对象。<br />
EaseSineIn 是按正弦函数缓动进入的动作。<br />
参考 easeInSine:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
action.easing(cc.easeSineIn());
```
*/
function easeSineIn(): any;
/**
!#en
Creates an EaseSineOut action easing object. <br />
Reference easeOutSine: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 EaseSineOut 缓动对象。<br />
EaseSineIn 是按正弦函数缓动退出的动作。<br />
参考 easeOutSine:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
action.easing(cc.easeSineOut());
```
*/
function easeSineOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInOutSine: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeSineInOut 缓动对象。<br />
EaseSineIn 是按正弦函数缓动进入并退出的动作。<br />
参考 easeInOutSine:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
action.easing(cc.easeSineInOut());
```
*/
function easeSineInOut(): any;
/**
!#en
Creates the action easing object with the period in radians (default is 0.3). <br />
Reference easeInElastic: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeElasticIn 缓动对象。<br />
EaseElasticIn 是按弹性曲线缓动进入的动作。<br />
参数 easeInElastic:http://www.zhihu.com/question/21981571/answer/19925418
@param period period
@example
```js
// example
action.easing(cc.easeElasticIn(3.0));
```
*/
function easeElasticIn(period: number): any;
/**
!#en
Creates the action easing object with the period in radians (default is 0.3). <br />
Reference easeOutElastic: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeElasticOut 缓动对象。<br />
EaseElasticOut 是按弹性曲线缓动退出的动作。<br />
参考 easeOutElastic:http://www.zhihu.com/question/21981571/answer/19925418
@param period period
@example
```js
// example
action.easing(cc.easeElasticOut(3.0));
```
*/
function easeElasticOut(period: number): any;
/**
!#en
Creates the action easing object with the period in radians (default is 0.3). <br />
Reference easeInOutElastic: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeElasticInOut 缓动对象。<br />
EaseElasticInOut 是按弹性曲线缓动进入并退出的动作。<br />
参考 easeInOutElastic:http://www.zhihu.com/question/21981571/answer/19925418
@param period period
@example
```js
// example
action.easing(cc.easeElasticInOut(3.0));
```
*/
function easeElasticInOut(period: number): any;
/**
!#en
Creates the action easing object. <br />
Eased bounce effect at the beginning.
!#zh
创建 easeBounceIn 缓动对象。<br />
EaseBounceIn 是按弹跳动作缓动进入的动作。
@example
```js
// example
action.easing(cc.easeBounceIn());
```
*/
function easeBounceIn(): any;
/**
!#en
Creates the action easing object. <br />
Eased bounce effect at the ending.
!#zh
创建 easeBounceOut 缓动对象。<br />
EaseBounceOut 是按弹跳动作缓动退出的动作。
@example
```js
// example
action.easing(cc.easeBounceOut());
```
*/
function easeBounceOut(): any;
/**
!#en
Creates the action easing object. <br />
Eased bounce effect at the begining and ending.
!#zh
创建 easeBounceInOut 缓动对象。<br />
EaseBounceInOut 是按弹跳动作缓动进入并退出的动作。
@example
```js
// example
action.easing(cc.easeBounceInOut());
```
*/
function easeBounceInOut(): any;
/**
!#en
Creates the action easing object. <br />
In the opposite direction to move slowly, and then accelerated to the right direction.
!#zh
创建 easeBackIn 缓动对象。<br />
easeBackIn 是在相反的方向缓慢移动,然后加速到正确的方向。<br />
@example
```js
// example
action.easing(cc.easeBackIn());
```
*/
function easeBackIn(): any;
/**
!#en
Creates the action easing object. <br />
Fast moving more than the finish, and then slowly back to the finish.
!#zh
创建 easeBackOut 缓动对象。<br />
easeBackOut 快速移动超出目标,然后慢慢回到目标点。
@example
```js
// example
action.easing(cc.easeBackOut());
```
*/
function easeBackOut(): any;
/**
!#en
Creates the action easing object. <br />
Begining of cc.EaseBackIn. Ending of cc.EaseBackOut.
!#zh
创建 easeBackInOut 缓动对象。<br />
@example
```js
// example
action.easing(cc.easeBackInOut());
```
*/
function easeBackInOut(): any;
/**
!#en
Creates the action easing object. <br />
Into the 4 reference point. <br />
To calculate the motion curve.
!#zh
创建 easeBezierAction 缓动对象。<br />
EaseBezierAction 是按贝塞尔曲线缓动的动作。
@param p0 The first bezier parameter
@param p1 The second bezier parameter
@param p2 The third bezier parameter
@param p3 The fourth bezier parameter
@example
```js
// example
action.easing(cc.easeBezierAction(0.5, 0.5, 1.0, 1.0));
```
*/
function easeBezierAction(p0: number, p1: number, p2: number, p3: number): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInQuad: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuadraticActionIn 缓动对象。<br />
EaseQuadraticIn是按二次函数缓动进入的动作。<br />
参考 easeInQuad:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeQuadraticActionIn());
```
*/
function easeQuadraticActionIn(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeOutQuad: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuadraticActionOut 缓动对象。<br />
EaseQuadraticOut 是按二次函数缓动退出的动作。<br />
参考 easeOutQuad:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeQuadraticActionOut());
```
*/
function easeQuadraticActionOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInOutQuad: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuadraticActionInOut 缓动对象。<br />
EaseQuadraticInOut 是按二次函数缓动进入并退出的动作。<br />
参考 easeInOutQuad:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeQuadraticActionInOut());
```
*/
function easeQuadraticActionInOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeIntQuart: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuarticActionIn 缓动对象。<br />
EaseQuarticIn 是按四次函数缓动进入的动作。<br />
参考 easeIntQuart:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeQuarticActionIn());
```
*/
function easeQuarticActionIn(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeOutQuart: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuarticActionOut 缓动对象。<br />
EaseQuarticOut 是按四次函数缓动退出的动作。<br />
参考 easeOutQuart:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.QuarticActionOut());
```
*/
function easeQuarticActionOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInOutQuart: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuarticActionInOut 缓动对象。<br />
EaseQuarticInOut 是按四次函数缓动进入并退出的动作。<br />
参考 easeInOutQuart:http://www.zhihu.com/question/21981571/answer/19925418
*/
function easeQuarticActionInOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInQuint: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuinticActionIn 缓动对象。<br />
EaseQuinticIn 是按五次函数缓动进的动作。<br />
参考 easeInQuint:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeQuinticActionIn());
```
*/
function easeQuinticActionIn(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeOutQuint: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuinticActionOut 缓动对象。<br />
EaseQuinticOut 是按五次函数缓动退出的动作
参考 easeOutQuint:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeQuadraticActionOut());
```
*/
function easeQuinticActionOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInOutQuint: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeQuinticActionInOut 缓动对象。<br />
EaseQuinticInOut是按五次函数缓动进入并退出的动作。<br />
参考 easeInOutQuint:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeQuinticActionInOut());
```
*/
function easeQuinticActionInOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInCirc: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeCircleActionIn 缓动对象。<br />
EaseCircleIn是按圆形曲线缓动进入的动作。<br />
参考 easeInCirc:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeCircleActionIn());
```
*/
function easeCircleActionIn(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeOutCirc: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeCircleActionOut 缓动对象。<br />
EaseCircleOut是按圆形曲线缓动退出的动作。<br />
参考 easeOutCirc:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
actioneasing(cc.easeCircleActionOut());
```
*/
function easeCircleActionOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInOutCirc: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeCircleActionInOut 缓动对象。<br />
EaseCircleInOut 是按圆形曲线缓动进入并退出的动作。<br />
参考 easeInOutCirc:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeCircleActionInOut());
```
*/
function easeCircleActionInOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInCubic: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeCubicActionIn 缓动对象。<br />
EaseCubicIn 是按三次函数缓动进入的动作。<br />
参考 easeInCubic:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeCubicActionIn());
```
*/
function easeCubicActionIn(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeOutCubic: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeCubicActionOut 缓动对象。<br />
EaseCubicOut 是按三次函数缓动退出的动作。<br />
参考 easeOutCubic:http://www.zhihu.com/question/21981571/answer/19925418
@example
```js
//example
action.easing(cc.easeCubicActionOut());
```
*/
function easeCubicActionOut(): any;
/**
!#en
Creates the action easing object. <br />
Reference easeInOutCubic: <br />
http://www.zhihu.com/question/21981571/answer/19925418
!#zh
创建 easeCubicActionInOut 缓动对象。<br />
EaseCubicInOut是按三次函数缓动进入并退出的动作。<br />
参考 easeInOutCubic:http://www.zhihu.com/question/21981571/answer/19925418
*/
function easeCubicActionInOut(): any;
/**
!#en Show the Node.
!#zh 立即显示。
@example
```js
// example
var showAction = cc.show();
```
*/
function show(): ActionInstant;
/**
!#en Hide the node.
!#zh 立即隐藏。
@example
```js
// example
var hideAction = cc.hide();
```
*/
function hide(): ActionInstant;
/**
!#en Toggles the visibility of a node.
!#zh 显隐状态切换。
@example
```js
// example
var toggleVisibilityAction = cc.toggleVisibility();
```
*/
function toggleVisibility(): ActionInstant;
/**
!#en Create a RemoveSelf object with a flag indicate whether the target should be cleaned up while removing.
!#zh 从父节点移除自身。
@param isNeedCleanUp isNeedCleanUp
@example
```js
// example
var removeSelfAction = cc.removeSelf();
```
*/
function removeSelf(isNeedCleanUp?: boolean): ActionInstant;
/**
!#en Destroy self
!#zh 创建一个销毁自身的动作。
@example
```js
var destroySelfAction = cc.destroySelf();
```
*/
function destroySelf(): ActionInstant;
/**
!#en Create a FlipX action to flip or unflip the target.
!#zh X轴翻转。
@param flip Indicate whether the target should be flipped or not
@example
```js
var flipXAction = cc.flipX(true);
```
*/
function flipX(flip: boolean): ActionInstant;
/**
!#en Create a FlipY action to flip or unflip the target.
!#zh Y轴翻转。
@param flip flip
@example
```js
var flipYAction = cc.flipY(true);
```
*/
function flipY(flip: boolean): ActionInstant;
/**
!#en Creates a Place action with a position.
!#zh 放置在目标位置。
@param pos pos
@param y y
@example
```js
// example
var placeAction = cc.place(cc.v2(200, 200));
var placeAction = cc.place(200, 200);
```
*/
function place(pos: Vec2 | number, y?: number): ActionInstant;
/**
!#en Creates the action with the callback.
!#zh 执行回调函数。
@param selector selector
@param selectorTarget selectorTarget
@param data data for function, it accepts all data types.
@example
```js
// example
// CallFunc without data
var finish = cc.callFunc(this.removeSprite, this);
// CallFunc with data
var finish = cc.callFunc(this.removeFromParentAndCleanup, this._grossini, true);
```
*/
function callFunc(selector: Function, selectorTarget?: any, data?: any): ActionInstant;
/**
!#en
Helper constructor to create an array of sequenceable actions
The created action will run actions sequentially, one after another.
!#zh 顺序执行动作,创建的动作将按顺序依次运行。
@param actionOrActionArray actionOrActionArray
@param tempArray tempArray
@example
```js
// example
// create sequence with actions
var seq = cc.sequence(act1, act2);
// create sequence with array
var seq = cc.sequence(actArray);
```
*/
function sequence(actionOrActionArray: FiniteTimeAction | FiniteTimeAction[], ...tempArray: FiniteTimeAction[]): ActionInterval;
/**
!#en Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30)
!#zh 重复动作,可以按一定次数重复一个动,如果想永远重复一个动作请使用 repeatForever 动作来完成。
@param action action
@param times times
@example
```js
// example
var rep = cc.repeat(cc.sequence(jump2, jump1), 5);
```
*/
function repeat(action: FiniteTimeAction, times: number): ActionInterval;
/**
!#en Create a acton which repeat forever, as it runs forever, it can't be added into cc.sequence and cc.spawn.
!#zh 永远地重复一个动作,有限次数内重复一个动作请使用 repeat 动作,由于这个动作不会停止,所以不能被添加到 cc.sequence 或 cc.spawn 中。
@param action action
@example
```js
// example
var repeat = cc.repeatForever(cc.rotateBy(1.0, 360));
```
*/
function repeatForever(action: FiniteTimeAction): ActionInterval;
/**
!#en Create a spawn action which runs several actions in parallel.
!#zh 同步执行动作,同步执行一组动作。
@param actionOrActionArray actionOrActionArray
@param tempArray tempArray
@example
```js
// example
var action = cc.spawn(cc.jumpBy(2, cc.v2(300, 0), 50, 4), cc.rotateBy(2, 720));
todo:It should be the direct use new
```
*/
function spawn(actionOrActionArray: FiniteTimeAction | FiniteTimeAction[], ...tempArray: FiniteTimeAction[]): FiniteTimeAction;
/**
!#en
Rotates a Node object to a certain angle by modifying its angle property. <br/>
The direction will be decided by the shortest angle.
!#zh 旋转到目标角度,通过逐帧修改它的 angle 属性,旋转方向将由最短的角度决定。
@param duration duration in seconds
@param dstAngle dstAngle in degrees.
@example
```js
// example
var rotateTo = cc.rotateTo(2, 61.0);
```
*/
function rotateTo(duration: number, dstAngle: number): ActionInterval;
/**
!#en
Rotates a Node object clockwise a number of degrees by modifying its angle property.
Relative to its properties to modify.
!#zh 旋转指定的角度。
@param duration duration in seconds
@param deltaAngle deltaAngle in degrees
@example
```js
// example
var actionBy = cc.rotateBy(2, 360);
```
*/
function rotateBy(duration: number, deltaAngle: number): ActionInterval;
/**
!#en
Moves a Node object x,y pixels by modifying its position property. <br/>
x and y are relative to the position of the object. <br/>
Several MoveBy actions can be concurrently called, and the resulting <br/>
movement will be the sum of individual movements.
!#zh 移动指定的距离。
@param duration duration in seconds
@param deltaPos deltaPos
@param deltaY deltaY
@example
```js
// example
var actionTo = cc.moveBy(2, cc.v2(windowSize.width - 40, windowSize.height - 40));
```
*/
function moveBy(duration: number, deltaPos: Vec2 | number, deltaY?: number): ActionInterval;
/**
!#en
Moves a Node object to the position x,y. x and y are absolute coordinates by modifying its position property. <br/>
Several MoveTo actions can be concurrently called, and the resulting <br/>
movement will be the sum of individual movements.
!#zh 移动到目标位置。
@param duration duration in seconds
@param position position
@param y y
@example
```js
// example
var actionBy = cc.moveTo(2, cc.v2(80, 80));
```
*/
function moveTo(duration: number, position: Vec2 | number, y?: number): ActionInterval;
/**
!#en
Create a action which skews a Node object to given angles by modifying its skewX and skewY properties.
Changes to the specified value.
!#zh 偏斜到目标角度。
@param t time in seconds
@param sx sx
@param sy sy
@example
```js
// example
var actionTo = cc.skewTo(2, 37.2, -37.2);
```
*/
function skewTo(t: number, sx: number, sy: number): ActionInterval;
/**
!#en
Skews a Node object by skewX and skewY degrees. <br />
Relative to its property modification.
!#zh 偏斜指定的角度。
@param t time in seconds
@param sx sx skew in degrees for X axis
@param sy sy skew in degrees for Y axis
@example
```js
// example
var actionBy = cc.skewBy(2, 0, -90);
```
*/
function skewBy(t: number, sx: number, sy: number): ActionInterval;
/**
!#en
Moves a Node object simulating a parabolic jump movement by modifying it's position property.
Relative to its movement.
!#zh 用跳跃的方式移动指定的距离。
@param duration duration
@param position position
@param y y
@param height height
@param jumps jumps
@example
```js
// example
var actionBy = cc.jumpBy(2, cc.v2(300, 0), 50, 4);
var actionBy = cc.jumpBy(2, 300, 0, 50, 4);
```
*/
function jumpBy(duration: number, position: Vec2 | number, y?: number, height?: number, jumps?: number): ActionInterval;
/**
!#en
Moves a Node object to a parabolic position simulating a jump movement by modifying its position property. <br />
Jump to the specified location.
!#zh 用跳跃的方式移动到目标位置。
@param duration duration
@param position position
@param y y
@param height height
@param jumps jumps
@example
```js
// example
var actionTo = cc.jumpTo(2, cc.v2(300, 300), 50, 4);
var actionTo = cc.jumpTo(2, 300, 300, 50, 4);
```
*/
function jumpTo(duration: number, position: Vec2 | number, y?: number, height?: number, jumps?: number): ActionInterval;
/**
!#en
An action that moves the target with a cubic Bezier curve by a certain distance.
Relative to its movement.
!#zh 按贝赛尔曲线轨迹移动指定的距离。
@param t time in seconds
@param c Array of points
@example
```js
// example
var bezier = [cc.v2(0, windowSize.height / 2), cc.v2(300, -windowSize.height / 2), cc.v2(300, 100)];
var bezierForward = cc.bezierBy(3, bezier);
```
*/
function bezierBy(t: number, c: Vec2[]): ActionInterval;
/**
!#en An action that moves the target with a cubic Bezier curve to a destination point.
!#zh 按贝赛尔曲线轨迹移动到目标位置。
@param t t
@param c Array of points
@example
```js
// example
var bezier = [cc.v2(0, windowSize.height / 2), cc.v2(300, -windowSize.height / 2), cc.v2(300, 100)];
var bezierTo = cc.bezierTo(2, bezier);
```
*/
function bezierTo(t: number, c: Vec2[]): ActionInterval;
/**
!#en Scales a Node object to a zoom factor by modifying it's scale property.
!#zh 将节点大小缩放到指定的倍数。
@param duration duration
@param sx scale parameter in X
@param sy scale parameter in Y, if Null equal to sx
@example
```js
// example
// It scales to 0.5 in both X and Y.
var actionTo = cc.scaleTo(2, 0.5);
// It scales to 0.5 in x and 2 in Y
var actionTo = cc.scaleTo(2, 0.5, 2);
```
*/
function scaleTo(duration: number, sx: number, sy?: number): ActionInterval;
/**
!#en
Scales a Node object a zoom factor by modifying it's scale property.
Relative to its changes.
!#zh 按指定的倍数缩放节点大小。
@param duration duration in seconds
@param sx sx scale parameter in X
@param sy sy scale parameter in Y, if Null equal to sx
@example
```js
// example without sy, it scales by 2 both in X and Y
var actionBy = cc.scaleBy(2, 2);
//example with sy, it scales by 0.25 in X and 4.5 in Y
var actionBy2 = cc.scaleBy(2, 0.25, 4.5);
```
*/
function scaleBy(duration: number, sx: number, sy?: number | void): ActionInterval;
/**
!#en Blinks a Node object by modifying it's visible property.
!#zh 闪烁(基于透明度)。
@param duration duration in seconds
@param blinks blinks in times
@example
```js
// example
var action = cc.blink(2, 10);
```
*/
function blink(duration: number, blinks: number): ActionInterval;
/**
!#en
Fades an object that implements the cc.RGBAProtocol protocol.
It modifies the opacity from the current value to a custom one.
!#zh 修改透明度到指定值。
@param duration duration
@param opacity 0-255, 0 is transparent
@example
```js
// example
var action = cc.fadeTo(1.0, 0);
```
*/
function fadeTo(duration: number, opacity: number): ActionInterval;
/**
!#en Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255.
!#zh 渐显效果。
@param duration duration in seconds
@example
```js
//example
var action = cc.fadeIn(1.0);
```
*/
function fadeIn(duration: number): ActionInterval;
/**
!#en Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0.
!#zh 渐隐效果。
@param d duration in seconds
@example
```js
// example
var action = cc.fadeOut(1.0);
```
*/
function fadeOut(d: number): ActionInterval;
/**
!#en Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
!#zh 修改颜色到指定值。
@param duration duration
@param red 0-255
@param green 0-255
@param blue 0-255
@example
```js
// example
var action = cc.tintTo(2, 255, 0, 255);
```
*/
function tintTo(duration: number, red: number, green: number, blue: number): ActionInterval;
/**
!#en
Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
Relative to their own color change.
!#zh 按照指定的增量修改颜色。
@param duration duration in seconds
@param deltaRed deltaRed
@param deltaGreen deltaGreen
@param deltaBlue deltaBlue
@example
```js
// example
var action = cc.tintBy(2, -127, -255, -127);
```
*/
function tintBy(duration: number, deltaRed: number, deltaGreen: number, deltaBlue: number): ActionInterval;
/**
!#en Delays the action a certain amount of seconds.
!#zh 延迟指定的时间量。
@param d duration in seconds
@example
```js
// example
var delay = cc.delayTime(1);
```
*/
function delayTime(d: number): ActionInterval;
/**
!#en Executes an action in reverse order, from time=duration to time=0.
!#zh 反转目标动作的时间轴。
@param action action
@example
```js
// example
var reverse = cc.reverseTime(this);
```
*/
function reverseTime(action: FiniteTimeAction): ActionInterval;
/**
!#en Create an action with the specified action and forced target.
!#zh 用已有动作和一个新的目标节点创建动作。
@param target target
@param action action
*/
function targetedAction(target: Node, action: FiniteTimeAction): ActionInterval;
/**
@param target the target to animate
*/
function tween<T>(target?: T): Tween<T>;
/**
!#en
Outputs an error message to the Cocos Creator Console (editor) or Web Console (runtime).<br/>
- In Cocos Creator, error is red.<br/>
- In Chrome, error have a red icon along with red message text.<br/>
!#zh
输出错误消息到 Cocos Creator 编辑器的 Console 或运行时页面端的 Console 中。<br/>
- 在 Cocos Creator 中,错误信息显示是红色的。<br/>
- 在 Chrome 中,错误信息有红色的图标以及红色的消息文本。<br/>
@param msg A JavaScript string containing zero or more substitution strings.
@param subst JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
*/
function error(msg: any, ...subst: any[]): void;
/**
!#en
Outputs a warning message to the Cocos Creator Console (editor) or Web Console (runtime).
- In Cocos Creator, warning is yellow.
- In Chrome, warning have a yellow warning icon with the message text.
!#zh
输出警告消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。<br/>
- 在 Cocos Creator 中,警告信息显示是黄色的。<br/>
- 在 Chrome 中,警告信息有着黄色的图标以及黄色的消息文本。<br/>
@param msg A JavaScript string containing zero or more substitution strings.
@param subst JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
*/
function warn(msg: any, ...subst: any[]): void;
/**
!#en Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime).
!#zh 输出一条消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。
@param msg A JavaScript string containing zero or more substitution strings.
@param subst JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
*/
function log(msg: string | any, ...subst: any[]): void;
/** !#en This is a Game instance.
!#zh 这是一个 Game 类的实例,包含游戏主体信息并负责驱动游戏的游戏对象。。 */
var game: Game;
/** !#en Director
!#zh 导演类。 */
var director: Director;
/** !#en This is a Easing instance.
!#zh 这是一个 Easing 类实例。 */
var easing: Easing;
/**
!#en
Rotates a Node object to a certain angle by modifying its quternion property. <br/>
The direction will be decided by the shortest angle.
!#zh 旋转到目标角度,通过逐帧修改它的 quternion 属性,旋转方向将由最短的角度决定。
@param duration duration in seconds
@param dstAngleX dstAngleX in degrees.
@param dstAngleY dstAngleY in degrees.
@param dstAngleZ dstAngleZ in degrees.
@example
```js
// example
var rotate3DTo = cc.rotate3DTo(2, cc.v3(0, 180, 0));
```
*/
function rotate3DTo(duration: number, dstAngleX: number | Vec3 | Quat, dstAngleY?: number, dstAngleZ?: number): ActionInterval;
/**
!#en
Rotates a Node object counter clockwise a number of degrees by modifying its quaternion property.
Relative to its properties to modify.
!#zh 旋转指定的 3D 角度。
@param duration duration in seconds
@param deltaAngleX deltaAngleX in degrees
@param deltaAngleY deltaAngleY in degrees
@param deltaAngleZ deltaAngleZ in degrees
@example
```js
// example
var actionBy = cc.rotate3DBy(2, cc.v3(0, 360, 0));
```
*/
function rotate3DBy(duration: number, deltaAngleX: number | Vec3, deltaAngleY?: number, deltaAngleZ?: number): ActionInterval;
var assetManager: AssetManager;
/** !#en
cc.resources is a bundle and controls all asset under assets/resources
!#zh
cc.resources 是一个 bundle,用于管理所有在 assets/resources 下的资源 */
var resources: AssetManager.Bundle;
/** !#en The System event singleton for global usage
!#zh 系统事件单例,方便全局使用 */
var systemEvent: SystemEvent;
/**
!#en Defines a CCClass using the given specification, please see [Class](/docs/editors_and_tools/creator-chapters/scripting/class.html) for details.
!#zh 定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅[类型定义](/docs/creator/scripting/class.html)。
@param options options
@example
```js
// define base class
var Node = cc.Class();
// define sub class
var Sprite = cc.Class({
name: 'Sprite',
extends: Node,
ctor: function () {
this.url = "";
this.id = 0;
},
statics: {
// define static members
count: 0,
getBounds: function (spriteList) {
// compute bounds...
}
},
properties {
width: {
default: 128,
type: cc.Integer,
tooltip: 'The width of sprite'
},
height: 128,
size: {
get: function () {
return cc.v2(this.width, this.height);
}
}
},
load: function () {
// load this.url...
};
});
// instantiate
var obj = new Sprite();
obj.url = 'sprite.png';
obj.load();
```
*/
function Class(options?: {
name?: string;
extends?: Function;
ctor?: Function;
__ctor__?: Function;
properties?: any;
statics?: any;
mixins?: Function[];
editor?: {
executeInEditMode?: boolean;
requireComponent?: Function;
menu?: string;
executionOrder?: number;
disallowMultiple?: boolean;
playOnFocus?: boolean;
inspector?: string;
icon?: string;
help?: string;
};
update?: Function;
lateUpdate?: Function;
onLoad?: Function;
start?: Function;
onEnable?: Function;
onDisable?: Function;
onDestroy?: Function;
onFocusInEditor?: Function;
onLostFocusInEditor?: Function;
resetInEditor?: Function;
onRestore?: Function;
_getLocalBounds?: Function;
}): Function;
/**
!#en
Define an enum type. <br/>
If a enum item has a value of -1, it will be given an Integer number according to it's order in the list.<br/>
Otherwise it will use the value specified by user who writes the enum definition.
!#zh
定义一个枚举类型。<br/>
用户可以把枚举值设为任意的整数,如果设为 -1,系统将会分配为上一个枚举值 + 1。
@param obj a JavaScript literal object containing enum names and values, or a TypeScript enum type
@example
```js
// JavaScript:
var WrapMode = cc.Enum({
Repeat: -1,
Clamp: -1
});
// Texture.WrapMode.Repeat == 0
// Texture.WrapMode.Clamp == 1
// Texture.WrapMode[0] == "Repeat"
// Texture.WrapMode[1] == "Clamp"
var FlagType = cc.Enum({
Flag1: 1,
Flag2: 2,
Flag3: 4,
Flag4: 8,
});
var AtlasSizeList = cc.Enum({
128: 128,
256: 256,
512: 512,
1024: 1024,
});
// TypeScript:
// If used in TypeScript, just define a TypeScript enum:
enum Direction {
Up,
Down,
Left,
Right
}
// If you need to inspect the enum in Properties panel, you can call cc.Enum:
const {ccclass, property} = cc._decorator;
@ccclass
class NewScript extends cc.Component {
@property({
type: cc.Enum(Direction) // call cc.Enum
})
direction: Direction = Direction.Up;
}
```
*/
function Enum<T>(obj: T): T;
/**
@param touches touches
*/
function handleTouchesBegin(touches: any[]): void;
/**
@param touches touches
*/
function handleTouchesMove(touches: any[]): void;
/**
@param touches touches
*/
function handleTouchesEnd(touches: any[]): void;
/**
@param touches touches
*/
function handleTouchesCancel(touches: any[]): void;
/**
@param touches touches
*/
function getSetOfTouchesEndOrCancel(touches: any[]): any[];
/**
@param touch touch
*/
function getPreTouch(touch: Touch): Touch;
/**
@param touch touch
*/
function setPreTouch(touch: Touch): void;
/**
@param tx tx
@param ty ty
@param pos pos
*/
function getTouchByXY(tx: number, ty: number, pos: Vec2): Touch;
/**
@param location location
@param pos pos
@param eventType eventType
*/
function getMouseEvent(location: Vec2, pos: Vec2, eventType: number): Event.EventMouse;
/**
@param event event
@param pos pos
*/
function getPointByEvent(event: Touch, pos: Vec2): Vec2;
/**
@param event event
@param pos pos
*/
function getTouchesByEvent(event: Touch, pos: Vec2): any[];
/**
@param element element
*/
function registerSystemEvent(element: HTMLElement): void;
/**
@param dt dt
*/
function update(dt: number): void;
/**
!#en
Checks whether the object is non-nil and not yet destroyed.<br>
When an object's `destroy` is called, it is actually destroyed after the end of this frame.
So `isValid` will return false from the next frame, while `isValid` in the current frame will still be true.
If you want to determine whether the current frame has called `destroy`, use `cc.isValid(obj, true)`,
but this is often caused by a particular logical requirements, which is not normally required.
!#zh
检查该对象是否不为 null 并且尚未销毁。<br>
当一个对象的 `destroy` 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 `isValid` 就会返回 false,而当前帧内 `isValid` 仍然会是 true。如果希望判断当前帧是否调用过 `destroy`,请使用 `cc.isValid(obj, true)`,不过这往往是特殊的业务需求引起的,通常情况下不需要这样。
@param value value
@param strictMode If true, Object called destroy() in this frame will also treated as invalid.
@example
```js
var node = new cc.Node();
cc.log(cc.isValid(node)); // true
node.destroy();
cc.log(cc.isValid(node)); // true, still valid in this frame
// after a frame...
cc.log(cc.isValid(node)); // false, destroyed in the end of last frame
```
*/
function isValid(value: any, strictMode?: boolean): boolean;
/** !#en cc.view is the shared view object.
!#zh cc.view 是全局的视图对象。 */
var view: View;
/** !#en cc.winSize is the alias object for the size of the current game window.
!#zh cc.winSize 为当前的游戏窗口的大小。 */
var winSize: Size;
/** Specify that the input value must be integer in Inspector.
Also used to indicates that the elements in array should be type integer. */
var Integer: string;
/** Indicates that the elements in array should be type double. */
var Float: string;
/** Indicates that the elements in array should be type boolean. */
var Boolean: string;
/** Indicates that the elements in array should be type string. */
var String: string;
/**
!#en Deserialize json to cc.Asset
!#zh 将 JSON 反序列化为对象实例。
@param data the serialized cc.Asset json string or json object.
@param details additional loading result
@param options options
*/
function deserialize(data: string | any, details?: Details, options?: any): any;
/**
!#en Clones the object `original` and returns the clone, or instantiate a node from the Prefab.
!#zh 克隆指定的任意类型的对象,或者从 Prefab 实例化出新节点。
(Instantiate 时,function 和 dom 等非可序列化对象会直接保留原有引用,Asset 会直接进行浅拷贝,可序列化类型会进行深拷贝。)
@param original An existing object that you want to make a copy of.
@example
```js
// instantiate node from prefab
var scene = cc.director.getScene();
var node = cc.instantiate(prefabAsset);
node.parent = scene;
// clone node
var scene = cc.director.getScene();
var node = cc.instantiate(targetNode);
node.parent = scene;
```
*/
function instantiate(original: Prefab): Node;
function instantiate<T>(original: T): T;
/**
!#en
The convenience method to create a new {{#crossLink "Color/Color:method"}}cc.Color{{/crossLink}}
Alpha channel is optional. Default value is 255.
!#zh
通过该方法来创建一个新的 {{#crossLink "Color/Color:method"}}cc.Color{{/crossLink}} 对象。
Alpha 通道是可选的。默认值是 255。
@param r r
@param g g
@param b b
@param a a
@example
```js
-----------------------
// 1. All channels seperately as parameters
var color1 = new cc.Color(255, 255, 255, 255);
// 2. Convert a hex string to a color
var color2 = new cc.Color("#000000");
// 3. An color object as parameter
var color3 = new cc.Color({r: 255, g: 255, b: 255, a: 255});
```
*/
function color(r?: number, g?: number, b?: number, a?: number): Color;
/**
!#en The convenience method to create a new {{#crossLink "Mat4"}}cc.Mat4{{/crossLink}}.
!#zh 通过该简便的函数进行创建 {{#crossLink "Mat4"}}cc.Mat4{{/crossLink}} 对象。
@param m00 Component in column 0, row 0 position (index 0)
@param m01 Component in column 0, row 1 position (index 1)
@param m02 Component in column 0, row 2 position (index 2)
@param m03 Component in column 0, row 3 position (index 3)
@param m10 Component in column 1, row 0 position (index 4)
@param m11 Component in column 1, row 1 position (index 5)
@param m12 Component in column 1, row 2 position (index 6)
@param m13 Component in column 1, row 3 position (index 7)
@param m20 Component in column 2, row 0 position (index 8)
@param m21 Component in column 2, row 1 position (index 9)
@param m22 Component in column 2, row 2 position (index 10)
@param m23 Component in column 2, row 3 position (index 11)
@param m30 Component in column 3, row 0 position (index 12)
@param m31 Component in column 3, row 1 position (index 13)
@param m32 Component in column 3, row 2 position (index 14)
@param m33 Component in column 3, row 3 position (index 15)
*/
function mat4(
m00?: number,
m01?: number,
m02?: number,
m03?: number,
m10?: number,
m11?: number,
m12?: number,
m13?: number,
m20?: number,
m21?: number,
m22?: number,
m23?: number,
m30?: number,
m31?: number,
m32?: number,
m33?: number
): Mat4;
/**
!#en The convenience method to create a new {{#crossLink "Quat"}}cc.Quat{{/crossLink}}.
!#zh 通过该简便的函数进行创建 {{#crossLink "Quat"}}cc.Quat{{/crossLink}} 对象。
@param x x
@param y y
@param z z
@param w w
*/
function quat(x?: number | any, y?: number, z?: number, w?: number): Quat;
/**
!#en
The convenience method to create a new Rect.
see {{#crossLink "Rect/Rect:method"}}cc.Rect{{/crossLink}}
!#zh
该方法用来快速创建一个新的矩形。{{#crossLink "Rect/Rect:method"}}cc.Rect{{/crossLink}}
@param x x
@param y y
@param w w
@param h h
@example
```js
var a = new cc.Rect(0 , 0, 10, 0);
```
*/
function rect(x?: number, y?: number, w?: number, h?: number): Rect;
/**
!#en
Helper function that creates a cc.Size.<br/>
Please use cc.p or cc.v2 instead, it will soon replace cc.Size.
!#zh
创建一个 cc.Size 对象的帮助函数。<br/>
注意:可以使用 cc.p 或者是 cc.v2 代替,它们将很快取代 cc.Size。
@param w width or a size object
@param h height
@example
```js
var size1 = cc.size();
var size2 = cc.size(100,100);
var size3 = cc.size(size2);
var size4 = cc.size({width: 100, height: 100});
```
*/
function size(w: number | Size, h?: number): Size;
var EPSILON: number;
/**
Clamps a value between a minimum float and maximum float value.
@param val val
@param min min
@param max max
*/
function clamp(val: number, min: number, max: number): number;
/**
Clamps a value between 0 and 1.
@param val val
*/
function clamp01(val: number): number;
/**
@param from from
@param to to
@param ratio the interpolation coefficient
*/
function lerp(from: number, to: number, ratio: number): number;
function random(): void;
/**
Returns a floating-point random number between min (inclusive) and max (exclusive).
@param min min
@param max max
*/
function randomRange(min: number, max: number): number;
/**
Returns a random integer between min (inclusive) and max (exclusive).
@param min min
@param max max
*/
function randomRangeInt(min: number, max: number): number;
/**
Linear congruential generator using Hull-Dobell Theorem.
@param seed the random seed
*/
function pseudoRandom(seed: number): number;
/**
Returns a floating-point pseudo-random number between min (inclusive) and max (exclusive).
@param seed seed
@param min min
@param max max
*/
function pseudoRandomRange(seed: number, min: number, max: number): number;
/**
Returns a pseudo-random integer between min (inclusive) and max (exclusive).
@param seed seed
@param min min
@param max max
*/
function pseudoRandomRangeInt(seed: number, min: number, max: number): number;
/**
Returns the next power of two for the value
@param val val
*/
function nextPow2(val: number): number;
/**
Returns float remainder for t / length
@param t time start at 0
@param length time of one cycle
*/
function repeat(t: number, length: number): number;
/**
Returns time wrapped in ping-pong mode
@param t time start at 0
@param length time of one cycle
*/
function repeat(t: number, length: number): number;
/**
Returns ratio of a value within a given range
@param from start value
@param to end value
@param value given value
*/
function repeat(from: number, to: number, value: number): number;
/**
Returns -1, 0, +1 depending on sign of x.
@param v v
*/
function sign(v: number): void;
/**
!#en The convenience method to create a new {{#crossLink "Vec2"}}cc.Vec2{{/crossLink}}.
!#zh 通过该简便的函数进行创建 {{#crossLink "Vec2"}}cc.Vec2{{/crossLink}} 对象。
@param x x
@param y y
@example
```js
var v1 = cc.v2();
var v2 = cc.v2(0, 0);
var v3 = cc.v2(v2);
var v4 = cc.v2({x: 100, y: 100});
```
*/
function v2(x?: number | any, y?: number): Vec2;
/**
!#en The convenience method to create a new {{#crossLink "Vec3"}}cc.Vec3{{/crossLink}}.
!#zh 通过该简便的函数进行创建 {{#crossLink "Vec3"}}cc.Vec3{{/crossLink}} 对象。
@param x x
@param y y
@param z z
@example
```js
var v1 = cc.v3();
var v2 = cc.v3(0, 0, 0);
var v3 = cc.v3(v2);
var v4 = cc.v3({x: 100, y: 100, z: 0});
```
*/
function v3(x?: number | any, y?: number, z?: number): Vec3;
/**
Finds a node by hierarchy path, the path is case-sensitive.
It will traverse the hierarchy by splitting the path using '/' character.
This function will still returns the node even if it is inactive.
It is recommended to not use this function every frame instead cache the result at startup.
@param path path
@param referenceNode referenceNode
*/
function find(path: string, referenceNode?: Node): Node;
var dynamicAtlasManager: DynamicAtlasManager;
/** !#en The matrix storage */
var matrix: any[];
/**
!#en Get an element
@param i i
@param j j
*/
function get(i: number, j: number): number;
/**
!#en Set an element
@param i i
@param j j
@param value value
*/
function set(i: number, j: number, value: boolean): void;
/**
!#en Sets all elements to zero
*/
function reset(): void;
/** !#en
cc.NodePool is the cache pool designed for node type.<br/>
It can helps you to improve your game performance for objects which need frequent release and recreate operations<br/>
It's recommended to create cc.NodePool instances by node type, the type corresponds to node type in game design, not the class,
for example, a prefab is a specific node type. <br/>
When you create a node pool, you can pass a Component which contains `unuse`, `reuse` functions to control the content of node.<br/>
Some common use case is :<br/>
1. Bullets in game (die very soon, massive creation and recreation, no side effect on other objects)<br/>
2. Blocks in candy crash (massive creation and recreation)<br/>
etc...
!#zh
cc.NodePool 是用于管理节点对象的对象缓存池。<br/>
它可以帮助您提高游戏性能,适用于优化对象的反复创建和销毁<br/>
以前 cocos2d-x 中的 cc.pool 和新的节点事件注册系统不兼容,因此请使用 cc.NodePool 来代替。
新的 NodePool 需要实例化之后才能使用,每种不同的节点对象池需要一个不同的对象池实例,这里的种类对应于游戏中的节点设计,一个 prefab 相当于一个种类的节点。<br/>
在创建缓冲池时,可以传入一个包含 unuse, reuse 函数的组件类型用于节点的回收和复用逻辑。<br/>
一些常见的用例是:<br/>
1.在游戏中的子弹(死亡很快,频繁创建,对其他对象无副作用)<br/>
2.糖果粉碎传奇中的木块(频繁创建)。
等等.... */
class NodePool {
/**
!#en
Constructor for creating a pool for a specific node template (usually a prefab). You can pass a component (type or name) argument for handling event for reusing and recycling node.
!#zh
使用构造函数来创建一个节点专用的对象池,您可以传递一个组件类型或名称,用于处理节点回收和复用时的事件逻辑。
@param poolHandlerComp !#en The constructor or the class name of the component to control the unuse/reuse logic. !#zh 处理节点回收和复用事件逻辑的组件类型或名称。
@example
```js
properties: {
template: cc.Prefab
},
onLoad () {
// MyTemplateHandler is a component with 'unuse' and 'reuse' to handle events when node is reused or recycled.
this.myPool = new cc.NodePool('MyTemplateHandler');
}
```
*/
constructor(poolHandlerComp?: { prototype: Component } | string);
/** !#en The pool handler component, it could be the class name or the constructor.
!#zh 缓冲池处理组件,用于节点的回收和复用逻辑,这个属性可以是组件类名或组件的构造函数。 */
poolHandlerComp: Function | string;
/**
!#en The current available size in the pool
!#zh 获取当前缓冲池的可用对象数量
*/
size(): number;
/**
!#en Destroy all cached nodes in the pool
!#zh 销毁对象池中缓存的所有节点
*/
clear(): void;
/**
!#en Put a new Node into the pool.
It will automatically remove the node from its parent without cleanup.
It will also invoke unuse method of the poolHandlerComp if exist.
!#zh 向缓冲池中存入一个不再需要的节点对象。
这个函数会自动将目标节点从父节点上移除,但是不会进行 cleanup 操作。
这个函数会调用 poolHandlerComp 的 unuse 函数,如果组件和函数都存在的话。
@param obj obj
@example
```js
let myNode = cc.instantiate(this.template);
this.myPool.put(myNode);
```
*/
put(obj: Node): void;
/**
!#en Get a obj from pool, if no available object in pool, null will be returned.
This function will invoke the reuse function of poolHandlerComp if exist.
!#zh 获取对象池中的对象,如果对象池没有可用对象,则返回空。
这个函数会调用 poolHandler