cc 模块
Cocos 引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。
类型
- Acceleration
- Action
- ActionEase
- ActionInstant
- ActionInterval
- ActionManager
- AffineTransform
- Animation
- AnimationClip
- AnimationState
- Asset
- AudioClip
- audioEngine
- AudioSource
- BitmapFont
- BlendFunc
- BlockInputEvents
- BoxCollider
- Button
- CallbacksInvoker
- Camera
- Canvas
- CircleCollider
- CoffeeScript
- Collider
- Collider.Box
- Collider.Circle
- Collider.Polygon
- CollisionManager
- Color
- Component
- Component.EventHandler
- ContainerStrategy
- ContentStrategy
- Details
- Director
- DistanceJoint
- EaseBounce
- EaseElastic
- EaseRateAction
- EditBox
- EqualToFrame
- EqualToWindow
- Event
- Event.EventAcceleration
- Event.EventCustom
- Event.EventKeyboard
- Event.EventMouse
- Event.EventTouch
- EventListener
- eventManager
- EventTarget
- FiniteTimeAction
- Font
- Game
- Graphics
- Intersection
- Joint
- JsonAsset
- Label
- LabelAtlas
- LabelOutline
- Layout
- loader
- LoadingItems
- Manifold
- ManifoldPoint
- Mask
- MotionStreak
- MotorJoint
- MouseJoint
- Node
- Node.EventType
- NodePool
- OriginalContainer
- PageView
- PageViewIndicator
- ParticleSystem
- PhysicsBoxCollider
- PhysicsChainCollider
- PhysicsCircleCollider
- PhysicsCollider
- PhysicsContact
- PhysicsImpulse
- PhysicsManager
- PhysicsPolygonCollider
- PhysicsRayCastResult
- Pipeline
- Pipeline.Downloader
- Pipeline.Loader
- Playable
- PolygonCollider
- pool
- Prefab
- PrismaticJoint
- ProgressBar
- ProportionalToFrame
- ProportionalToWindow
- Quad2
- Quad3
- RawAsset
- Rect
- ResolutionPolicy
- RevoluteJoint
- RichText
- RigidBody
- RopeJoint
- Scene
- SceneAsset
- Scheduler
- screen
- Scrollbar
- ScrollView
- Size
- Slider
- Sprite
- SpriteAtlas
- SpriteDistortion
- SpriteFrame
- sys
- SystemEvent
- SystemEvent.EventType
- Tex2F
- TextAsset
- Texture2D
- textureCache
- TiledLayer
- TiledMap
- TiledMapAsset
- TiledObjectGroup
- TMXObject
- Toggle
- ToggleContainer
- ToggleGroup
- Touch
- TTFFont
- TypeScript
- url
- V2F_C4B_T2F
- V2F_C4B_T2F_Triangle
- V3F_C4B_T2F
- V3F_C4B_T2F_Quad
- ValueType
- Vec2
- Vertex2F
- Vertex3F
- VideoPlayer
- View
- ViewGroup
- visibleRect
- WebGLColor
- WebView
- WeldJoint
- WheelJoint
- Widget
- WorldManifold
枚举
- audioEngine.AudioState
- BlendFactor
- Button.Transition
- DebugMode
- DrawBits
- EditBox.InputFlag
- EditBox.InputMode
- EditBox.KeyboardReturnType
- Flags
- Graphics.LineCap
- Graphics.LineJoin
- ImageFormat
- KEY
- Label.HorizontalAlign
- Label.Overflow
- Label.Type
- Label.VerticalAlign
- Layout.AxisDirection
- Layout.HorizontalDirection
- Layout.ResizeMode
- Layout.Type
- Layout.VerticalDirection
- LoadingItems.ItemState
- macro
- Mask.Type
- NetworkType
- PageView.Direction
- PageView.EventType
- PageView.SizeMode
- PageViewIndicator.Direction
- ParticleSystem.EmitterMode
- ParticleSystem.PositionType
- Prefab.OptimizationPolicy
- ProgressBar.Mode
- RayCastType
- RigidBodyType
- Scrollbar.Direction
- ScrollView.EventType
- Slider.Direction
- Sprite.FillType
- Sprite.SizeMode
- Sprite.Type
- TextAlignment
- Texture2D.Filter
- Texture2D.PixelFormat
- Texture2D.WrapMode
- TiledMap.Orientation
- VideoPlayer.EventType
- VideoPlayer.ResourceType
- WebView.EventType
- Widget.AlignMode
- WrapMode
索引
属性(properties)
_renderContextCanvasRenderingContext2D|WebGLRenderingContextmain Canvas 2D/3D Context of game engine_canvasHTMLCanvasElementMain canvas of game enginecontainerHTMLDivElementThe element contains the game canvasENGINE_VERSIONStringThe current version of Cocos2d being used....viewViewcc.view 是全局的视图对象。directorDirector导演类。winSizeSizecc.winSize 为当前的游戏窗口的大小。gameGameIntegerstringSpecify that the input value must be integer in Inspector....FloatstringIndicates that the elements in array should be type double.BooleanstringIndicates that the elements in array should be type boolean.StringstringIndicates that the elements in array should be type string.systemEventSystemEvent系统事件单例,方便全局使用
方法
_initDebugSetting设置调试模式。error输出错误消息到 Cocos Creator 编辑器的 Console 或运行时页面端的 Console 中。warn输出警告消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。log输出一条消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。speed修改目标动作的速率。follow追踪目标节点的位置。setPointsPoints settercardinalSplineTo按基数样条曲线轨迹移动到目标位置。updatePositionupdate position of targetcardinalSplineBy按基数样条曲线轨迹移动指定的距离。catmullRomTo按 Catmull Rom 样条曲线轨迹移动到目标位置。catmullRomBy按 Catmull Rom 样条曲线轨迹移动指定的距离。show立即显示。hide立即隐藏。toggleVisibility显隐状态切换。removeSelf从父节点移除自身。flipXX轴翻转。flipYY轴翻转。place放置在目标位置。callFunc执行回调函数。sequence顺序执行动作,创建的动作将按顺序依次运行。repeat重复动作,可以按一定次数重复一个动,如果想永远重复一个动作请使用 repeatForever 动作来完成。repeatForever永远地重复一个动作,有限次数内重复一个动作请使用 repeat 动作,由于这个动作不会停止,所以不能被添加到 cc.sequence 或 cc.spawn 中。spawn同步执行动作,同步执行一组动作。rotateTo旋转到目标角度,通过逐帧修改它的 rotation 属性,旋转方向将由最短的角度决定。rotateBy旋转指定的角度。moveBy移动指定的距离。moveTo移动到目标位置。skewTo偏斜到目标角度。skewBy偏斜指定的角度。jumpBy用跳跃的方式移动指定的距离。jumpTo用跳跃的方式移动到目标位置。bezierBy按贝赛尔曲线轨迹移动指定的距离。bezierTo按贝赛尔曲线轨迹移动到目标位置。scaleTo将节点大小缩放到指定的倍数。scaleBy按指定的倍数缩放节点大小。blink闪烁(基于透明度)。fadeTo修改透明度到指定值。fadeIn渐显效果。fadeOut渐隐效果。tintTo修改颜色到指定值。tintBy按照指定的增量修改颜色。delayTimereverseTime反转目标动作的时间轴。targetedAction用已有动作和一个新的目标节点创建动作。easeIn创建 easeIn 缓动对象,由慢到快。easeOut创建 easeOut 缓动对象,由快到慢。easeInOut创建 easeInOut 缓动对象,慢到快,然后慢。easeExponentialIn创建 easeExponentialIn 缓动对象。easeExponentialOut创建 easeExponentialOut 缓动对象。easeExponentialInOut创建 easeExponentialInOut 缓动对象。easeSineIn创建 EaseSineIn 缓动对象。easeSineOut创建 EaseSineOut 缓动对象。easeSineInOut创建 easeSineInOut 缓动对象。easeElasticIn创建 easeElasticIn 缓动对象。easeElasticOut创建 easeElasticOut 缓动对象。easeElasticInOut创建 easeElasticInOut 缓动对象。easeBounceIn创建 easeBounceIn 缓动对象。easeBounceOut创建 easeBounceOut 缓动对象。easeBounceInOut创建 easeBounceInOut 缓动对象。easeBackIn创建 easeBackIn 缓动对象。easeBackOut创建 easeBackOut 缓动对象。easeBackInOut创建 easeBackInOut 缓动对象。easeBezierAction创建 easeBezierAction 缓动对象。easeQuadraticActionIn创建 easeQuadraticActionIn 缓动对象。easeQuadraticActionOut创建 easeQuadraticActionOut 缓动对象。easeQuadraticActionInOut创建 easeQuadraticActionInOut 缓动对象。easeQuarticActionIn创建 easeQuarticActionIn 缓动对象。easeQuarticActionOut创建 easeQuarticActionOut 缓动对象。easeQuarticActionInOut创建 easeQuarticActionInOut 缓动对象。easeQuinticActionIn创建 easeQuinticActionIn 缓动对象。easeQuinticActionOut创建 easeQuinticActionOut 缓动对象。easeQuinticActionInOut创建 easeQuinticActionInOut 缓动对象。easeCircleActionIn创建 easeCircleActionIn 缓动对象。easeCircleActionOut创建 easeCircleActionOut 缓动对象。easeCircleActionInOut创建 easeCircleActionInOut 缓动对象。easeCubicActionIn创建 easeCubicActionIn 缓动对象。easeCubicActionOut创建 easeCubicActionOut 缓动对象。easeCubicActionInOut创建 easeCubicActionInOut 缓动对象。handleTouchesBeginhandleTouchesMovehandleTouchesEndhandleTouchesCancelgetSetOfTouchesEndOrCancelgetHTMLElementPositiongetPreTouchsetPreTouchgetTouchByXYgetPointByEventgetTouchesByEventregisterSystemEventClass定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅类型定义。_isCCClassChecks whether the constructor is created by cc.ClassisChildClassOfChecks whether subclass is child of superclass or equals to superclassEnum定义一个枚举类型。getListsetAccelerometerEnabledwhether enable accelerometer eventsetAccelerometerIntervalset accelerometer interval valuehandleTouchesBeginhandleTouchesMovehandleTouchesEndhandleTouchesCancelgetSetOfTouchesEndOrCancelgetHTMLElementPositiongetPreTouchsetPreTouchgetTouchByXYgetTouchByXYgetPointByEventgetTouchesByEventregisterSystemEventupdatelerpLinear interpolation between 2 numbers, the ratio sets how much it is biased to each endrandget a random number from 0 to 0xffffffrandomMinus1To1returns a random float between -1 and 1random0To1returns a random float between 0 and 1, use Math.random directlydegreesToRadiansconverts degrees to radiansradiansToDegreesconverts radians to degreesnodeDrawSetupHelpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrixincrementGLDraws...
checkGLErrorDebugCheck webgl error.Error will be shown in console if exists.isValid检查该对象是否不为 null 并且尚未销毁。deserialize将 JSON 反序列化为对象实例。instantiate克隆指定的任意类型的对象,或者从 Prefab 实例化出新节点。findFinds a node by hierarchy path, the path is case-sensitive....pNeg返回相反的向量。pAdd返回两个向量的和。pSub返回两个向量的差。pMult向量缩放。pMidpoint两个向量之间的中心点。pDot两个向量之间进行点乘。pCross两个向量之间进行叉乘。pPerp返回逆时针旋转 90 度后的新向量。pRPerp将指定向量顺时针旋转 90 度并返回。pProject返回 v1 在 v2 上的投影向量。pLengthSQ返回指定向量长度的平方。pDistanceSQ返回两个点之间距离的平方。pLength返回指定向量的长度.pDistance返回指定 2 个向量之间的距离。pNormalize返回一个长度为 1 的标准化过后的向量。pForAngle将弧度转换为一个标准化后的向量,返回坐标 x = cos(a) , y = sin(a)。pToAngle返回指定向量的弧度。clampf限定浮点数的最大最小值。clamp01限定浮点数的取值范围为 0 ~ 1 之间。pClamp返回指定限制区域后的向量。pFromSize快速转换 cc.Size 为 cc.Vec2。pCompOp通过运行指定的数学运算函数来计算指定的向量。pLerp两个点 A 和 B 之间的线性插值。pFuzzyEqual近似判断两个点是否相等。pCompMult计算两个向量的每个分量的乘积, a.x b.x, a.y b.y。pAngleSigned返回两个向量之间带正负号的弧度。pAngle获取当前向量与指定向量之间的弧度角。pRotateByAngle返回给定向量围绕指定轴心顺时针旋转一定弧度后的结果。pLineIntersect如果相交返回 true,反之则为 false,参数 retP 是返回交点在线段 1、线段 2 上的比例。pSegmentIntersect返回线段 A - B 和线段 C - D 是否相交。pIntersectPoint返回线段 A - B 和线段 C - D 的交点。pSameAs检查指定的 2 个向量是否相等。pZeroIn设置指定向量归 0。pIn令 v1 向量等同于 v2。pMultIn向量缩放,结果保存到第一个向量。pSubIn向量减法,结果保存到第一个向量。pAddIn向量加法,结果保存到第一个向量。pNormalizeIn规范化 v 向量,设置 v 向量长度为 1。color通过该方法来创建一个新的 Color/Color:method 对象。colorEqual判断两个颜色对象的 RGB 部分是否相等,不比较透明度。hexToColor16 进制转换为 ColorcolorToHexColor 转换为 16进制。rect该方法用来快速创建一个新的矩形。rectEqualToRect判断两个矩形是否相等。rectContainsRect检查 rect1 矩形是否包含 rect2 矩形。rectGetMaxX返回矩形在 x 轴上的最大值rectGetMidX返回矩形在 x 轴上的中点。rectGetMinX返回矩形在 x 轴上的最小值。rectGetMaxY返回矩形在 y 轴上的最大值。rectGetMidY返回矩形在 y 轴上的中点。rectGetMinY返回矩形在 y 轴上的最小值。rectContainsPoint检查一个矩形是否包含某个坐标点。rectIntersectsRect检查一个矩形是否与另一个相交。rectOverlapsRect检查一个矩形是否重叠另一个。rectUnion返回一个包含两个指定矩形的最小矩形。rectIntersection返回 2 个矩形重叠的部分。size创建一个 cc.Size 对象的帮助函数。sizeEqualToSize检查 Size 对象是否等于另一个。V3F_C4B_T2F_QuadZeroV3F_C4B_T2F_QuadCopyV3F_C4B_T2F_QuadsCopyv2通过该简便的函数进行创建 cc.Vec2 对象。p通过该简便的函数进行创建 cc.Vec2 对象。pointEqualToPoint判断两个向量是否相等。
Details
属性(properties)
_renderContext
main Canvas 2D/3D Context of game engine
| meta | description |
|---|---|
| 类型 | CanvasRenderingContext2D | WebGLRenderingContext |
| 定义于 | CCBoot.js:30 |
_canvas
Main canvas of game engine
| meta | description |
|---|---|
| 类型 | HTMLCanvasElement |
| 定义于 | CCBoot.js:37 |
container
The element contains the game canvas
| meta | description |
|---|---|
| 类型 | HTMLDivElement |
| 定义于 | CCBoot.js:43 |
ENGINE_VERSION
The current version of Cocos2d being used.
Please DO NOT remove this String, it is an important flag for bug tracking.
If you post a bug to forum, please attach this flag.
| meta | description |
|---|---|
| 类型 | String |
| 定义于 | predefine.js:156 |
view
cc.view 是全局的视图对象。
| meta | description |
|---|---|
| 类型 | View |
| 定义于 | cocos2d/core/CCGame.js:378 |
director
导演类。
| meta | description |
|---|---|
| 类型 | Director |
| 定义于 | cocos2d/core/CCGame.js:386 |
winSize
cc.winSize 为当前的游戏窗口的大小。
| meta | description |
|---|---|
| 类型 | Size |
| 定义于 | cocos2d/core/CCGame.js:395 |
game
| meta | description |
|---|---|
| 类型 | Game |
| 定义于 | cocos2d/core/CCGame.js:848 |
Integer
Specify that the input value must be integer in Inspector. Also used to indicates that the elements in array should be type integer.
| meta | description |
|---|---|
| 类型 | string |
| 定义于 | cocos2d/core/platform/attribute.js:153 |
示例
// in cc.Class
member: {
default: [],
type: cc.Integer
}
// ES6 ccclass
Float
Indicates that the elements in array should be type double.
| meta | description |
|---|---|
| 类型 | string |
| 定义于 | cocos2d/core/platform/attribute.js:172 |
示例
// in cc.Class
member: {
default: [],
type: cc.Float
}
// ES6 ccclass
Boolean
Indicates that the elements in array should be type boolean.
| meta | description |
|---|---|
| 类型 | string |
| 定义于 | cocos2d/core/platform/attribute.js:197 |
示例
// in cc.Class
member: {
default: [],
type: cc.Boolean
}
// ES6 ccclass
String
Indicates that the elements in array should be type string.
| meta | description |
|---|---|
| 类型 | string |
| 定义于 | cocos2d/core/platform/attribute.js:215 |
示例
// in cc.Class
member: {
default: [],
type: cc.String
}
// ES6 ccclass
systemEvent
系统事件单例,方便全局使用
| meta | description |
|---|---|
| 类型 | SystemEvent |
| 定义于 | cocos2d/core/event/system-event.js:195 |
方法
_initDebugSetting
设置调试模式。
| meta | description |
|---|---|
| 定义于 | CCDebugger.js:103 |
参数列表
modeDebugMode
error
输出错误消息到 Cocos Creator 编辑器的 Console 或运行时页面端的 Console 中。
- 在 Cocos Creator 中,错误信息显示是红色的。
- 在 Chrome 中,错误信息有红色的图标以及红色的消息文本。
| meta | description |
|---|---|
| 定义于 | CCDebugger.js:181 |
参数列表
msgAny A JavaScript string containing zero or more substitution strings.substAny JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
warn
输出警告消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。
- 在 Cocos Creator 中,警告信息显示是黄色的。
- 在 Chrome 中,警告信息有着黄色的图标以及黄色的消息文本。
| meta | description |
|---|---|
| 定义于 | CCDebugger.js:225 |
参数列表
msgAny A JavaScript string containing zero or more substitution strings.substAny JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
log
输出一条消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。
| meta | description |
|---|---|
| 定义于 | CCDebugger.js:255 |
参数列表
msgString | Any A JavaScript string containing zero or more substitution strings.substAny JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
speed
修改目标动作的速率。
| meta | description |
|---|---|
| 返回 | Action |
| 定义于 | cocos2d/actions/CCAction.js:367 |
参数列表
actionActionIntervalspeedNumber
示例
// change the target action speed;
var action = cc.scaleTo(0.2, 1, 0.6);
var newAction = cc.speed(action, 0.5);
follow
追踪目标节点的位置。
| meta | description |
|---|---|
| 返回 | Action | Null |
| 定义于 | cocos2d/actions/CCAction.js:562 |
参数列表
示例
// 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);
setPoints
Points setter
| meta | description |
|---|---|
| 定义于 | cocos2d/actions/CCActionCatmullRom.js:225 |
参数列表
pointsArray
cardinalSplineTo
按基数样条曲线轨迹移动到目标位置。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionCatmullRom.js:235 |
参数列表
示例
//create a cc.CardinalSplineTo
var action1 = cc.cardinalSplineTo(3, array, 0);
updatePosition
update position of target
| meta | description |
|---|---|
| 定义于 | cocos2d/actions/CCActionCatmullRom.js:319 |
参数列表
newPosVec2
cardinalSplineBy
按基数样条曲线轨迹移动指定的距离。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionCatmullRom.js:340 |
参数列表
catmullRomTo
按 Catmull Rom 样条曲线轨迹移动到目标位置。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionCatmullRom.js:386 |
参数列表
示例
var action1 = cc.catmullRomTo(3, array);
catmullRomBy
按 Catmull Rom 样条曲线轨迹移动指定的距离。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionCatmullRom.js:434 |
参数列表
示例
var action1 = cc.catmullRomBy(3, array);
show
立即显示。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:98 |
示例
// example
var showAction = cc.show();
hide
立即隐藏。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:135 |
示例
// example
var hideAction = cc.hide();
toggleVisibility
显隐状态切换。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:172 |
示例
// example
var toggleVisibilityAction = cc.toggleVisibility();
removeSelf
从父节点移除自身。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:222 |
参数列表
isNeedCleanUpBoolean
示例
// example
var removeSelfAction = cc.removeSelf();
flipX
X轴翻转。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:280 |
参数列表
flipBoolean Indicate whether the target should be flipped or not
示例
var flipXAction = cc.flipX(true);
flipY
Y轴翻转。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:336 |
参数列表
flipBoolean
示例
var flipYAction = cc.flipY(true);
place
放置在目标位置。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:400 |
参数列表
示例
// example
var placeAction = cc.place(cc.p(200, 200));
var placeAction = cc.place(200, 200);
callFunc
执行回调函数。
| meta | description |
|---|---|
| 返回 | ActionInstant |
| 定义于 | cocos2d/actions/CCActionInstant.js:510 |
参数列表
示例
// example
// CallFunc without data
var finish = cc.callFunc(this.removeSprite, this);
// CallFunc with data
var finish = cc.callFunc(this.removeFromParentAndCleanup, this._grossini, true);
sequence
顺序执行动作,创建的动作将按顺序依次运行。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:440 |
参数列表
actionOrActionArrayFiniteTimeAction | FiniteTimeAction[]tempArrayFiniteTimeAction
示例
// example
// create sequence with actions
var seq = cc.sequence(act1, act2);
// create sequence with array
var seq = cc.sequence(actArray);
repeat
重复动作,可以按一定次数重复一个动,如果想永远重复一个动作请使用 repeatForever 动作来完成。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:618 |
参数列表
actionFiniteTimeActiontimesNumber
示例
// example
var rep = cc.repeat(cc.sequence(jump2, jump1), 5);
repeatForever
永远地重复一个动作,有限次数内重复一个动作请使用 repeat 动作,由于这个动作不会停止,所以不能被添加到 cc.sequence 或 cc.spawn 中。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:721 |
参数列表
actionFiniteTimeAction
示例
// example
var repeat = cc.repeatForever(cc.rotateBy(1.0, 360));
spawn
同步执行动作,同步执行一组动作。
| meta | description |
|---|---|
| 返回 | FiniteTimeAction |
| 定义于 | cocos2d/actions/CCActionInterval.js:835 |
参数列表
actionOrActionArrayFiniteTimeAction | FiniteTimeAction[]tempArrayFiniteTimeAction
示例
// example
var action = cc.spawn(cc.jumpBy(2, cc.p(300, 0), 50, 4), cc.rotateBy(2, 720));
todo:It should be the direct use new
rotateTo
旋转到目标角度,通过逐帧修改它的 rotation 属性,旋转方向将由最短的角度决定。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:956 |
参数列表
durationNumber duration in secondsdeltaAngleXNumber deltaAngleX in degrees.deltaAngleYNumber deltaAngleY in degrees.
示例
// example
var rotateTo = cc.rotateTo(2, 61.0);
rotateBy
旋转指定的角度。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1043 |
参数列表
durationNumber duration in secondsdeltaAngleXNumber deltaAngleX in degreesdeltaAngleYNumber deltaAngleY in degrees
示例
// example
var actionBy = cc.rotateBy(2, 360);
moveBy
移动指定的距离。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1162 |
参数列表
示例
// example
var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40));
moveTo
移动到目标位置。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1240 |
参数列表
示例
// example
var actionBy = cc.moveTo(2, cc.p(80, 80));
skewTo
偏斜到目标角度。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1334 |
参数列表
示例
// example
var actionTo = cc.skewTo(2, 37.2, -37.2);
skewBy
偏斜指定的角度。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1408 |
参数列表
tNumber time in secondssxNumber sx skew in degrees for X axissyNumber sy skew in degrees for Y axis
示例
// example
var actionBy = cc.skewBy(2, 0, -90);
jumpBy
用跳跃的方式移动指定的距离。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1537 |
参数列表
示例
// example
var actionBy = cc.jumpBy(2, cc.p(300, 0), 50, 4);
var actionBy = cc.jumpBy(2, 300, 0, 50, 4);
jumpTo
用跳跃的方式移动到目标位置。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1620 |
参数列表
示例
// example
var actionTo = cc.jumpTo(2, cc.p(300, 300), 50, 4);
var actionTo = cc.jumpTo(2, 300, 300, 50, 4);
bezierBy
按贝赛尔曲线轨迹移动指定的距离。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1766 |
参数列表
示例
// example
var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
var bezierForward = cc.bezierBy(3, bezier);
bezierTo
按贝赛尔曲线轨迹移动到目标位置。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1835 |
参数列表
示例
// example
var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
var bezierTo = cc.bezierTo(2, bezier);
scaleTo
将节点大小缩放到指定的倍数。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1920 |
参数列表
示例
// 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);
scaleBy
按指定的倍数缩放节点大小。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:1967 |
参数列表
durationNumber duration in secondssxNumber sx scale parameter in XsyNumber | Null sy scale parameter in Y, if Null equal to sx
示例
// 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);
blink
闪烁(基于透明度)。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2052 |
参数列表
示例
// example
var action = cc.blink(2, 10);
fadeTo
修改透明度到指定值。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2118 |
参数列表
示例
// example
var action = cc.fadeTo(1.0, 0);
fadeIn
渐显效果。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2173 |
参数列表
durationNumber duration in seconds
示例
//example
var action = cc.fadeIn(1.0);
fadeOut
渐隐效果。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2220 |
参数列表
dNumber duration in seconds
示例
// example
var action = cc.fadeOut(1.0);
tintTo
修改颜色到指定值。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2307 |
参数列表
示例
// example
var action = cc.tintTo(2, 255, 0, 255);
tintBy
按照指定的增量修改颜色。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2400 |
参数列表
示例
// example
var action = cc.tintBy(2, -127, -255, -127);
delayTime
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2441 |
参数列表
dNumber duration in seconds
示例
// example
var delay = cc.delayTime(1);
reverseTime
反转目标动作的时间轴。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2524 |
参数列表
actionFiniteTimeAction
示例
// example
var reverse = cc.reverseTime(this);
targetedAction
用已有动作和一个新的目标节点创建动作。
| meta | description |
|---|---|
| 返回 | ActionInterval |
| 定义于 | cocos2d/actions/CCActionInterval.js:2781 |
参数列表
targetNodeactionFiniteTimeAction
easeIn
创建 easeIn 缓动对象,由慢到快。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:198 |
参数列表
rateNumber
示例
action.easing(cc.easeIn(3.0));
easeOut
创建 easeOut 缓动对象,由快到慢。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:248 |
参数列表
rateNumber
示例
action.easing(cc.easeOut(3.0));
easeInOut
创建 easeInOut 缓动对象,慢到快,然后慢。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:302 |
参数列表
rateNumber
示例
action.easing(cc.easeInOut(3.0));
easeExponentialIn
创建 easeExponentialIn 缓动对象。
EaseExponentialIn 是按指数函数缓动进入的动作。
参考 easeInExpo:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:367 |
示例
action.easing(cc.easeExponentialIn());
easeExponentialOut
创建 easeExponentialOut 缓动对象。
EaseExponentialOut 是按指数函数缓动退出的动作。
参考 easeOutExpo:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:422 |
示例
action.easing(cc.easeExponentialOut());
easeExponentialInOut
创建 easeExponentialInOut 缓动对象。
EaseExponentialInOut 是按指数函数缓动进入并退出的动作。
参考 easeInOutExpo:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:492 |
示例
action.easing(cc.easeExponentialInOut());
easeSineIn
创建 EaseSineIn 缓动对象。
EaseSineIn 是按正弦函数缓动进入的动作。
参考 easeInSine:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:547 |
示例
action.easing(cc.easeSineIn());
easeSineOut
创建 EaseSineOut 缓动对象。
EaseSineIn 是按正弦函数缓动退出的动作。
参考 easeOutSine:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:603 |
示例
action.easing(cc.easeSineOut());
easeSineInOut
创建 easeSineInOut 缓动对象。
EaseSineIn 是按正弦函数缓动进入并退出的动作。
参考 easeInOutSine:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:659 |
示例
action.easing(cc.easeSineInOut());
easeElasticIn
创建 easeElasticIn 缓动对象。
EaseElasticIn 是按弹性曲线缓动进入的动作。
参数 easeInElastic:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:788 |
参数列表
periodNumber
示例
// example
action.easing(cc.easeElasticIn(3.0));
easeElasticOut
创建 easeElasticOut 缓动对象。
EaseElasticOut 是按弹性曲线缓动退出的动作。
参考 easeOutElastic:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:868 |
参数列表
periodNumber
示例
// example
action.easing(cc.easeElasticOut(3.0));
easeElasticInOut
创建 easeElasticInOut 缓动对象。
EaseElasticInOut 是按弹性曲线缓动进入并退出的动作。
参考 easeInOutElastic:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:944 |
参数列表
periodNumber
示例
// example
action.easing(cc.easeElasticInOut(3.0));
easeBounceIn
创建 easeBounceIn 缓动对象。
EaseBounceIn 是按弹跳动作缓动进入的动作。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1082 |
示例
// example
action.easing(cc.easeBounceIn());
easeBounceOut
创建 easeBounceOut 缓动对象。
EaseBounceOut 是按弹跳动作缓动退出的动作。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1137 |
示例
// example
action.easing(cc.easeBounceOut());
easeBounceInOut
创建 easeBounceInOut 缓动对象。
EaseBounceInOut 是按弹跳动作缓动进入并退出的动作。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1205 |
示例
// example
action.easing(cc.easeBounceInOut());
easeBackIn
创建 easeBackIn 缓动对象。
easeBackIn 是在相反的方向缓慢移动,然后加速到正确的方向。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1262 |
示例
// example
action.easing(cc.easeBackIn());
easeBackOut
创建 easeBackOut 缓动对象。
easeBackOut 快速移动超出目标,然后慢慢回到目标点。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1320 |
示例
// example
action.easing(cc.easeBackOut());
easeBackInOut
创建 easeBackInOut 缓动对象。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1388 |
示例
// example
action.easing(cc.easeBackInOut());
easeBezierAction
创建 easeBezierAction 缓动对象。
EaseBezierAction 是按贝塞尔曲线缓动的动作。
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1470 |
参数列表
p0Number The first bezier parameterp1Number The second bezier parameterp2Number The third bezier parameterp3Number The fourth bezier parameter
示例
// example
action.easing(cc.easeBezierAction(0.5, 0.5, 1.0, 1.0));
easeQuadraticActionIn
创建 easeQuadraticActionIn 缓动对象。
EaseQuadraticIn是按二次函数缓动进入的动作。
参考 easeInQuad:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1540 |
示例
//example
action.easing(cc.easeQuadraticActionIn());
easeQuadraticActionOut
创建 easeQuadraticActionOut 缓动对象。
EaseQuadraticOut 是按二次函数缓动退出的动作。
参考 easeOutQuad:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1598 |
示例
//example
action.easing(cc.easeQuadraticActionOut());
easeQuadraticActionInOut
创建 easeQuadraticActionInOut 缓动对象。
EaseQuadraticInOut 是按二次函数缓动进入并退出的动作。
参考 easeInOutQuad:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1664 |
示例
//example
action.easing(cc.easeQuadraticActionInOut());
easeQuarticActionIn
创建 easeQuarticActionIn 缓动对象。
EaseQuarticIn 是按四次函数缓动进入的动作。
参考 easeIntQuart:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1721 |
示例
//example
action.easing(cc.easeQuarticActionIn());
easeQuarticActionOut
创建 easeQuarticActionOut 缓动对象。
EaseQuarticOut 是按四次函数缓动退出的动作。
参考 easeOutQuart:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1780 |
示例
//example
action.easing(cc.QuarticActionOut());
easeQuarticActionInOut
创建 easeQuarticActionInOut 缓动对象。
EaseQuarticInOut 是按四次函数缓动进入并退出的动作。
参考 easeInOutQuart:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1841 |
easeQuinticActionIn
创建 easeQuinticActionIn 缓动对象。
EaseQuinticIn 是按五次函数缓动进的动作。
参考 easeInQuint:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1896 |
示例
//example
action.easing(cc.easeQuinticActionIn());
easeQuinticActionOut
创建 easeQuinticActionOut 缓动对象。
EaseQuinticOut 是按五次函数缓动退出的动作
参考 easeOutQuint:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:1955 |
示例
//example
action.easing(cc.easeQuadraticActionOut());
easeQuinticActionInOut
创建 easeQuinticActionInOut 缓动对象。
EaseQuinticInOut是按五次函数缓动进入并退出的动作。
参考 easeInOutQuint:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:2017 |
示例
//example
action.easing(cc.easeQuinticActionInOut());
easeCircleActionIn
创建 easeCircleActionIn 缓动对象。
EaseCircleIn是按圆形曲线缓动进入的动作。
参考 easeInCirc:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:2075 |
示例
//example
action.easing(cc.easeCircleActionIn());
easeCircleActionOut
创建 easeCircleActionOut 缓动对象。
EaseCircleOut是按圆形曲线缓动退出的动作。
参考 easeOutCirc:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:2134 |
示例
//example
actioneasing(cc.easeCircleActionOut());
easeCircleActionInOut
创建 easeCircleActionInOut 缓动对象。
EaseCircleInOut 是按圆形曲线缓动进入并退出的动作。
参考 easeInOutCirc:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:2196 |
示例
//example
action.easing(cc.easeCircleActionInOut());
easeCubicActionIn
创建 easeCubicActionIn 缓动对象。
EaseCubicIn 是按三次函数缓动进入的动作。
参考 easeInCubic:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:2254 |
示例
//example
action.easing(cc.easeCubicActionIn());
easeCubicActionOut
创建 easeCubicActionOut 缓动对象。
EaseCubicOut 是按三次函数缓动退出的动作。
参考 easeOutCubic:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:2313 |
示例
//example
action.easing(cc.easeCubicActionOut());
easeCubicActionInOut
创建 easeCubicActionInOut 缓动对象。
EaseCubicInOut是按三次函数缓动进入并退出的动作。
参考 easeInOutCubic:http://www.zhihu.com/question/21981571/answer/19925418
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/actions/CCActionEase.js:2375 |
handleTouchesBegin
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/BKInputManager.js:90 |
参数列表
touchesArray
handleTouchesMove
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/BKInputManager.js:125 |
参数列表
touchesArray
handleTouchesEnd
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/BKInputManager.js:157 |
参数列表
touchesArray
handleTouchesCancel
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/BKInputManager.js:171 |
参数列表
touchesArray
getSetOfTouchesEndOrCancel
| meta | description |
|---|---|
| 返回 | Array |
| 定义于 | cocos2d/core/platform/BKInputManager.js:185 |
参数列表
touchesArray
getHTMLElementPosition
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/core/platform/BKInputManager.js:212 |
参数列表
elementHTMLElement
getPreTouch
| meta | description |
|---|---|
| 返回 | Touch |
| 定义于 | cocos2d/core/platform/BKInputManager.js:250 |
参数列表
touchTouch
setPreTouch
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/BKInputManager.js:270 |
参数列表
touchTouch
getTouchByXY
| meta | description |
|---|---|
| 返回 | Touch |
| 定义于 | cocos2d/core/platform/BKInputManager.js:296 |
参数列表
getPointByEvent
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/platform/BKInputManager.js:313 |
参数列表
getTouchesByEvent
| meta | description |
|---|---|
| 返回 | Array |
| 定义于 | cocos2d/core/platform/BKInputManager.js:335 |
参数列表
registerSystemEvent
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/BKInputManager.js:419 |
参数列表
elementHTMLElement
Class
定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅类型定义。
| meta | description |
|---|---|
| 返回 | Function |
| 定义于 | cocos2d/core/platform/CCClass.js:829 |
参数列表
optionsObjectnameString The class name used for serialization.extendsFunction The base class.ctorFunction The constructor.__ctor__Function The same as ctor, but less encapsulated.propertiesObject The property definitions.staticsObject The static members.mixinsFunction[]editorObject attributes for Component listed below.executeInEditModeBoolean Allows the current component to run in edit mode. By default, all components are executed only at runtime, meaning that they will not have their callback functions executed while the Editor is in edit mode.requireComponentFunction Automatically add required component as a dependency.menuString The menu path to register a component to the editors "Component" menu. Eg. "Rendering/Camera".executionOrderNumber The execution order of lifecycle methods for Component. Those less than 0 will execute before while those greater than 0 will execute after. The order will only affect onLoad, onEnable, start, update and lateUpdate while onDisable and onDestroy will not be affected.disallowMultipleBoolean If specified to a type, prevents Component of the same type (or subtype) to be added more than once to a Node.playOnFocusBoolean This property is only available when executeInEditMode is set. If specified, the editor's scene view will keep updating this node in 60 fps when it is selected, otherwise, it will update only if necessary.inspectorString Customize the page url used by the current component to render in the Properties.iconString Customize the icon that the current component displays in the editor.helpString The custom documentation URL
updateFunction lifecycle method for Component, see updatelateUpdateFunction lifecycle method for Component, see lateUpdateonLoadFunction lifecycle method for Component, see onLoadstartFunction lifecycle method for Component, see startonEnableFunction lifecycle method for Component, see onEnableonDisableFunction lifecycle method for Component, see onDisableonDestroyFunction lifecycle method for Component, see onDestroyonFocusInEditorFunction lifecycle method for Component, see onFocusInEditoronLostFocusInEditorFunction lifecycle method for Component, see onLostFocusInEditorresetInEditorFunction lifecycle method for Component, see resetInEditoronRestoreFunction for Component only, see onRestore_getLocalBoundsFunction for Component only, see _getLocalBounds
示例
// 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: '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();
_isCCClass
Checks whether the constructor is created by cc.Class
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCClass.js:1000 |
参数列表
constructorFunction
isChildClassOf
Checks whether subclass is child of superclass or equals to superclass
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCClass.js:1037 |
参数列表
Enum
定义一个枚举类型。
用户可以把枚举值设为任意的整数,如果设为 -1,系统将会分配为上一个枚举值 + 1。
| meta | description |
|---|---|
| 返回 | object |
| 定义于 | cocos2d/core/platform/CCEnum.js:34 |
参数列表
objobject a JavaScript literal object containing enum names and values, or a TypeScript enum type
示例
// 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;
}
getList
| meta | description |
|---|---|
| 返回 | Object[] |
| 定义于 | cocos2d/core/platform/CCEnum.js:90 |
参数列表
enumDefObject the enum type defined from cc.Enum
setAccelerometerEnabled
whether enable accelerometer event
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputExtension.js:41 |
参数列表
isEnableBoolean
setAccelerometerInterval
set accelerometer interval value
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputExtension.js:64 |
参数列表
intervalNumber
handleTouchesBegin
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputManager.js:99 |
参数列表
touchesArray
handleTouchesMove
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputManager.js:134 |
参数列表
touchesArray
handleTouchesEnd
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputManager.js:166 |
参数列表
touchesArray
handleTouchesCancel
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputManager.js:181 |
参数列表
touchesArray
getSetOfTouchesEndOrCancel
| meta | description |
|---|---|
| 返回 | Array |
| 定义于 | cocos2d/core/platform/CCInputManager.js:196 |
参数列表
touchesArray
getHTMLElementPosition
| meta | description |
|---|---|
| 返回 | Object |
| 定义于 | cocos2d/core/platform/CCInputManager.js:222 |
参数列表
elementHTMLElement
getPreTouch
| meta | description |
|---|---|
| 返回 | Touch |
| 定义于 | cocos2d/core/platform/CCInputManager.js:269 |
参数列表
touchTouch
setPreTouch
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputManager.js:289 |
参数列表
touchTouch
getTouchByXY
| meta | description |
|---|---|
| 返回 | Touch |
| 定义于 | cocos2d/core/platform/CCInputManager.js:314 |
参数列表
getTouchByXY
| meta | description |
|---|---|
| 返回 | Event.EventMouse |
| 定义于 | cocos2d/core/platform/CCInputManager.js:331 |
参数列表
getPointByEvent
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/platform/CCInputManager.js:349 |
参数列表
getTouchesByEvent
| meta | description |
|---|---|
| 返回 | Array |
| 定义于 | cocos2d/core/platform/CCInputManager.js:370 |
参数列表
registerSystemEvent
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputManager.js:408 |
参数列表
elementHTMLElement
update
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCInputManager.js:599 |
参数列表
dtNumber
lerp
Linear interpolation between 2 numbers, the ratio sets how much it is biased to each end
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCMacro.js:2001 |
参数列表
示例
----
lerp
cc.lerp(2,10,0.5)//returns 6
cc.lerp(2,10,0.2)//returns 3.6
rand
get a random number from 0 to 0xffffff
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCMacro.js:2016 |
randomMinus1To1
returns a random float between -1 and 1
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCMacro.js:2025 |
random0To1
returns a random float between 0 and 1, use Math.random directly
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCMacro.js:2034 |
degreesToRadians
converts degrees to radians
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCMacro.js:2041 |
参数列表
angleNumber
radiansToDegrees
converts radians to degrees
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCMacro.js:2051 |
参数列表
angleNumber
nodeDrawSetup
Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCMacro.js:2061 |
参数列表
nodeNode setup node
incrementGLDraws
Increments the GL Draws counts by one.
The number of calls per frame are displayed on the screen when the CCDirector's stats are enabled.
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCMacro.js:2113 |
参数列表
addNumberNumber
checkGLErrorDebug
Check webgl error.Error will be shown in console if exists.
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCMacro.js:2125 |
isValid
检查该对象是否不为 null 并且尚未销毁。
当一个对象的 destroy 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 isValid 就会返回 false,而当前帧内 isValid 仍然会是 true。如果希望判断当前帧是否调用过 destroy,请使用 cc.isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCObject.js:509 |
参数列表
valueAnystrictModeBoolean If true, Object called destroy() in this frame will also treated as invalid.
示例
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
deserialize
将 JSON 反序列化为对象实例。
当指定了 target 选项时,如果 target 引用的其它 asset 的 uuid 不变,则不会改变 target 对 asset 的引用, 也不会将 uuid 保存到 result 对象中。
| meta | description |
|---|---|
| 返回 | object |
| 定义于 | cocos2d/core/platform/deserialize.js:741 |
参数列表
dataString | Object the serialized cc.Asset json string or json object.detailsDetails additional loading resultoptionsObject
instantiate
克隆指定的任意类型的对象,或者从 Prefab 实例化出新节点。
(Instantiate 时,function 和 dom 等非可序列化对象会直接保留原有引用,Asset 会直接进行浅拷贝,可序列化类型会进行深拷贝。)
| meta | description |
|---|---|
| 返回 | Node | Object |
| 定义于 | cocos2d/core/platform/instantiate.js:36 |
参数列表
示例
// 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;
find
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.
| meta | description |
|---|---|
| 返回 | Node | Null |
| 定义于 | cocos2d/core/utils/find.js:30 |
参数列表
pNeg
返回相反的向量。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:47 |
参数列表
pointVec2
示例
cc.pNeg(cc.v2(10, 10));// Vec2 {x: -10, y: -10};
pAdd
返回两个向量的和。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:60 |
参数列表
示例
cc.pAdd(cc.v2(1, 1), cc.v2(2, 2));// Vec2 {x: 3, y: 3};
pSub
返回两个向量的差。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:74 |
参数列表
示例
cc.pSub(cc.v2(20, 20), cc.v2(5, 5)); // Vec2 {x: 15, y: 15};
pMult
向量缩放。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:88 |
参数列表
示例
cc.pMult(cc.v2(5, 5), 4); // Vec2 {x: 20, y: 20};
pMidpoint
两个向量之间的中心点。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:102 |
参数列表
示例
cc.pMidpoint(cc.v2(10, 10), cc.v2(5, 5)); // Vec2 {x: 7.5, y: 7.5};
pDot
两个向量之间进行点乘。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:116 |
参数列表
示例
cc.pDot(cc.v2(20, 20), cc.v2(5, 5)); // 200;
pCross
两个向量之间进行叉乘。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:130 |
参数列表
示例
cc.pCross(cc.v2(20, 20), cc.v2(5, 5)); // 0;
pPerp
返回逆时针旋转 90 度后的新向量。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:144 |
参数列表
pointVec2
示例
cc.pPerp(cc.v2(20, 20)); // Vec2 {x: -20, y: 20};
pRPerp
将指定向量顺时针旋转 90 度并返回。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:157 |
参数列表
pointVec2
示例
cc.pRPerp(cc.v2(20, 20)); // Vec2 {x: 20, y: -20};
pProject
返回 v1 在 v2 上的投影向量。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:170 |
参数列表
示例
var v1 = cc.v2(20, 20);
var v2 = cc.v2(5, 5);
cc.pProject(v1, v2); // Vec2 {x: 20, y: 20};
pLengthSQ
返回指定向量长度的平方。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:186 |
参数列表
vVec2
示例
cc.pLengthSQ(cc.v2(20, 20)); // 800;
pDistanceSQ
返回两个点之间距离的平方。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:199 |
参数列表
示例
var point1 = cc.v2(20, 20);
var point2 = cc.v2(5, 5);
cc.pDistanceSQ(point1, point2); // 450;
pLength
返回指定向量的长度.
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:215 |
参数列表
vVec2
示例
cc.pLength(cc.v2(20, 20)); // 28.284271247461902;
pDistance
返回指定 2 个向量之间的距离。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:228 |
参数列表
示例
var v1 = cc.v2(20, 20);
var v2 = cc.v2(5, 5);
cc.pDistance(v1, v2); // 21.213203435596427;
pNormalize
返回一个长度为 1 的标准化过后的向量。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:244 |
参数列表
vVec2
示例
cc.pNormalize(cc.v2(20, 20)); // Vec2 {x: 0.7071067811865475, y: 0.7071067811865475};
pForAngle
将弧度转换为一个标准化后的向量,返回坐标 x = cos(a) , y = sin(a)。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:258 |
参数列表
aNumber
示例
cc.pForAngle(20); // Vec2 {x: 0.40808206181339196, y: 0.9129452507276277};
pToAngle
返回指定向量的弧度。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:271 |
参数列表
vVec2
示例
cc.pToAngle(cc.v2(20, 20)); // 0.7853981633974483;
clampf
限定浮点数的最大最小值。
数值大于 max_inclusive 则返回 max_inclusive。
数值小于 min_inclusive 则返回 min_inclusive。
否则返回自身。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:284 |
参数列表
示例
var v1 = cc.clampf(20, 0, 20); // 20;
var v2 = cc.clampf(-1, 0, 20); // 0;
var v3 = cc.clampf(10, 0, 20); // 10;
clamp01
限定浮点数的取值范围为 0 ~ 1 之间。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:310 |
参数列表
valueNumber
示例
var v1 = cc.clampf(20); // 1;
var v2 = cc.clampf(-1); // 0;
var v3 = cc.clampf(0.5); // 0.5;
pClamp
返回指定限制区域后的向量。
向量大于 max_inclusive 则返回 max_inclusive。
向量小于 min_inclusive 则返回 min_inclusive。
否则返回自身。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:325 |
参数列表
示例
var min_inclusive = cc.v2(0, 0);
var max_inclusive = cc.v2(20, 20);
var v1 = cc.pClamp(cc.v2(20, 20), min_inclusive, max_inclusive); // Vec2 {x: 20, y: 20};
var v2 = cc.pClamp(cc.v2(0, 0), min_inclusive, max_inclusive); // Vec2 {x: 0, y: 0};
var v3 = cc.pClamp(cc.v2(10, 10), min_inclusive, max_inclusive); // Vec2 {x: 10, y: 10};
pFromSize
快速转换 cc.Size 为 cc.Vec2。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:348 |
参数列表
sSize
示例
cc.pFromSize(new cc.size(20, 20)); // Vec2 {x: 20, y: 20};
pCompOp
通过运行指定的数学运算函数来计算指定的向量。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:361 |
参数列表
示例
cc.pCompOp(cc.p(-10, -10), Math.abs); // Vec2 {x: 10, y: 10};
pLerp
两个点 A 和 B 之间的线性插值。
alpha == 0 ? a
alpha == 1 ? b
否则这个数值在 a ~ b 之间。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:377 |
参数列表
示例
cc.pLerp(cc.v2(20, 20), cc.v2(5, 5), 0.5); // Vec2 {x: 12.5, y: 12.5};
pFuzzyEqual
近似判断两个点是否相等。
判断 2 个向量是否在指定数值的范围之内,如果在则返回 true,反之则返回 false。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:400 |
参数列表
示例
var a = cc.v2(20, 20);
var b = cc.v2(5, 5);
var b1 = cc.pFuzzyEqual(a, b, 10); // false;
var b2 = cc.pFuzzyEqual(a, b, 18); // true;
pCompMult
计算两个向量的每个分量的乘积, a.x b.x, a.y b.y。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:424 |
参数列表
示例
cc.pCompMult(acc.v2(20, 20), cc.v2(5, 5)); // Vec2 {x: 100, y: 100};
pAngleSigned
返回两个向量之间带正负号的弧度。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:438 |
参数列表
pAngle
获取当前向量与指定向量之间的弧度角。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:455 |
参数列表
pRotateByAngle
返回给定向量围绕指定轴心顺时针旋转一定弧度后的结果。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:469 |
参数列表
vVec2 v is the point to rotatepivotVec2 pivot is the pivot, naturallyangleNumber angle is the angle of rotation cw in radians
pLineIntersect
返回 A 为起点 B 为终点线段 1 所在直线和 C 为起点 D 为终点线段 2 所在的直线是否相交,
如果相交返回 true,反之则为 false,参数 retP 是返回交点在线段 1、线段 2 上的比例。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:487 |
参数列表
AVec2 A is the startpoint for the first line P1 = (p1 - p2).BVec2 B is the endpoint for the first line P1 = (p1 - p2).CVec2 C is the startpoint for the second line P2 = (p3 - p4).DVec2 D is the endpoint for the second line P2 = (p3 - p4).retPVec2 retP.x is the range for a hitpoint in P1 (pa = p1 + s(p2 - p1)),
retP.y is the range for a hitpoint in P3 (pa = p2 + t(p4 - p3)).
pSegmentIntersect
返回线段 A - B 和线段 C - D 是否相交。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:538 |
参数列表
pIntersectPoint
返回线段 A - B 和线段 C - D 的交点。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:556 |
参数列表
pSameAs
检查指定的 2 个向量是否相等。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:580 |
参数列表
pZeroIn
设置指定向量归 0。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:599 |
参数列表
vVec2
pIn
令 v1 向量等同于 v2。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:610 |
参数列表
pMultIn
向量缩放,结果保存到第一个向量。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:622 |
参数列表
pSubIn
向量减法,结果保存到第一个向量。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:634 |
参数列表
pAddIn
向量加法,结果保存到第一个向量。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:646 |
参数列表
pNormalizeIn
规范化 v 向量,设置 v 向量长度为 1。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/CCPointExtension.js:658 |
参数列表
vVec2
color
通过该方法来创建一个新的 Color/Color:method 对象。 Alpha 通道是可选的。默认值是 255。
| meta | description |
|---|---|
| 返回 | Color |
| 定义于 | cocos2d/core/value-types/CCColor.js:621 |
参数列表
示例
-----------------------
// 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});
colorEqual
判断两个颜色对象的 RGB 部分是否相等,不比较透明度。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCColor.js:652 |
参数列表
示例
cc.log(cc.colorEqual(cc.Color.RED, new cc.Color(255, 0, 0))); // true
hexToColor
16 进制转换为 Color
| meta | description |
|---|---|
| 返回 | Color |
| 定义于 | cocos2d/core/value-types/CCColor.js:671 |
参数列表
hexString
示例
cc.hexToColor("#FFFF33"); // Color {r: 255, g: 255, b: 51, a: 255};
colorToHex
Color 转换为 16进制。
| meta | description |
|---|---|
| 返回 | String |
| 定义于 | cocos2d/core/value-types/CCColor.js:691 |
参数列表
colorColor
示例
var color = new cc.Color(255, 6, 255)
cc.colorToHex(color); // #ff06ff;
rect
该方法用来快速创建一个新的矩形。Rect/Rect:method
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/CCRect.js:370 |
参数列表
示例
var a = new cc.Rect(0 , 0, 10, 0);
rectEqualToRect
判断两个矩形是否相等。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCRect.js:392 |
参数列表
示例
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Rect(0, 0, 5, 5);
cc.rectEqualToRect(a, b); // false;
var c = new cc.Rect(0, 0, 5, 5);
cc.rectEqualToRect(b, c); // true;
rectContainsRect
检查 rect1 矩形是否包含 rect2 矩形。
注意:如果要允许 rect1 和 rect2 的边界重合,应该用 cc.rectOverlapsRect
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCRect.js:414 |
参数列表
示例
var a = new cc.Rect(0, 0, 20, 20);
var b = new cc.Rect(10, 10, 20, 20);
cc.rectContainsRect(a, b); // true;
rectGetMaxX
返回矩形在 x 轴上的最大值
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCRect.js:436 |
参数列表
rectRect
示例
var a = new cc.Rect(10, 0, 20, 20);
cc.rectGetMaxX(a); // 30;
rectGetMidX
返回矩形在 x 轴上的中点。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCRect.js:450 |
参数列表
rectRect
示例
var a = new cc.Rect(10, 0, 20, 20);
cc.rectGetMidX(a); // 20;
rectGetMinX
返回矩形在 x 轴上的最小值。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCRect.js:463 |
参数列表
rectRect
示例
var a = new cc.Rect(10, 0, 20, 20);
cc.rectGetMinX(a); // 10;
rectGetMaxY
返回矩形在 y 轴上的最大值。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCRect.js:477 |
参数列表
rectRect
示例
var a = new cc.Rect(0, 10, 20, 20);
cc.rectGetMaxY(a); // 30;
rectGetMidY
返回矩形在 y 轴上的中点。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCRect.js:491 |
参数列表
rectRect
示例
var a = new cc.Rect(0, 10, 20, 20);
cc.rectGetMidY(a); // 20;
rectGetMinY
返回矩形在 y 轴上的最小值。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/value-types/CCRect.js:505 |
参数列表
rectRect
示例
var a = new cc.Rect(0, 10, 20, 20);
cc.rectGetMinY(a); // 10;
rectContainsPoint
检查一个矩形是否包含某个坐标点。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCRect.js:519 |
参数列表
示例
var a = new cc.Rect(0, 10, 20, 20);
var b = new cc.Vec2(0, 10, 10, 10);
cc.rectContainsPoint(a, b); // true;
rectIntersectsRect
检查一个矩形是否与另一个相交。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCRect.js:536 |
参数列表
示例
var a = new cc.Rect(0, 10, 20, 20);
var b = new cc.Rect(0, 10, 10, 10);
cc.rectIntersectsRect(a, b); // true;
rectOverlapsRect
检查一个矩形是否重叠另一个。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCRect.js:556 |
参数列表
示例
var a = new cc.Rect(0, 10, 20, 20);
var b = new cc.Rect(0, 10, 10, 10);
cc.rectOverlapsRect(a, b); // true;
rectUnion
返回一个包含两个指定矩形的最小矩形。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/CCRect.js:575 |
参数列表
示例
var a = new cc.Rect(0, 10, 20, 20);
var b = new cc.Rect(0, 10, 10, 10);
cc.rectUnion(a, b); // Rect {x: 0, y: 10, width: 20, height: 20};
rectIntersection
返回 2 个矩形重叠的部分。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/CCRect.js:596 |
参数列表
示例
var a = new cc.Rect(0, 10, 20, 20);
var b = new cc.Rect(0, 10, 10, 10);
cc.rectIntersection(a, b); // Rect {x: 0, y: 10, width: 10, height: 10};
size
创建一个 cc.Size 对象的帮助函数。
注意:可以使用 cc.p 或者是 cc.v2 代替,它们将很快取代 cc.Size。
| meta | description |
|---|---|
| 返回 | Size |
| 定义于 | cocos2d/core/value-types/CCSize.js:158 |
参数列表
示例
var size1 = cc.size();
var size2 = cc.size(100,100);
var size3 = cc.size(size2);
var size4 = cc.size({width: 100, height: 100});
sizeEqualToSize
检查 Size 对象是否等于另一个。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCSize.js:175 |
参数列表
示例
var a = new cc.size(10, 10);
var b = new cc.size(10, 10);
cc.sizeEqualToSize(a, b);// return true;
var b = new cc.size(5, 10);
cc.sizeEqualToSize(a, b);// return false;
V3F_C4B_T2F_QuadZero
| meta | description |
|---|---|
| 返回 | V3F_C4B_T2F_Quad |
| 定义于 | cocos2d/core/value-types/CCTypesWebGL.js:502 |
V3F_C4B_T2F_QuadCopy
| meta | description |
|---|---|
| 返回 | V3F_C4B_T2F_Quad |
| 定义于 | cocos2d/core/value-types/CCTypesWebGL.js:510 |
参数列表
sourceQuadV3F_C4B_T2F_Quad
V3F_C4B_T2F_QuadsCopy
| meta | description |
|---|---|
| 返回 | Array |
| 定义于 | cocos2d/core/value-types/CCTypesWebGL.js:537 |
参数列表
sourceQuadsArray
v2
通过该简便的函数进行创建 cc.Vec2 对象。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCVec2.js:589 |
参数列表
示例
var v1 = cc.v2();
var v2 = cc.v2(0, 0);
var v3 = cc.v2(v2);
var v4 = cc.v2({x: 100, y: 100});
p
通过该简便的函数进行创建 cc.Vec2 对象。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/value-types/CCVec2.js:606 |
参数列表
示例
var point1 = cc.p();
var point2 = cc.p(100, 100);
var point3 = cc.p(point2);
var point4 = cc.p({x: 100, y: 100});
pointEqualToPoint
判断两个向量是否相等。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/CCVec2.js:624 |