首页 > 代码库 > 【cocos2d-js官方文档】十八、Cocos2d-JS v3.0中的属性风格API

【cocos2d-js官方文档】十八、Cocos2d-JS v3.0中的属性风格API

1. 新的API风格

我们直接来看看你可以如何使用Cocos2d-JS v3.0:

以前的API新的API
node.setPosition(x, y);node.x = x;
node.y = y;
node.setRotation(r);node.rotation = r;

如表格中可以看到的,设置position属性的函数调用在3.0版中会被替换为直接的对象属性存取。不仅仅是示例中的xyrotation,几乎所有节点类型中关于属性存取的函数都会被替换为直接的对象属性访问。具体的属性列表在文档最后。

得益于JavaScript的getter/setter,我们可以为对象的某一个属性名分别设置其getter/setter函数。这就是Cocos2d-JS如何做到从函数到属性的转换。比如说,node.x = x;实际上调用了setPositionX函数并传入x作为参数,所以在使用属性风格API的时候请不要因为它的简单而感到担心,在很多情况下这等同于以前的函数调用。

你也可以给自己的对象属性定义getter/setter函数,只需要使用下面这行代码:

cc.defineGetterSetter(object, "propertyName", getterFunc, setterFunc);

这样的话,var a = object.propertyName;会通过getterFunc获取propertyName的当前值,object.propertyName = newvalue;则会通过setterFunc来给propertyName赋新值。

至于属性的命名,我们尽可能提供了类似css风格的属性名,除此之外的属性都尽力维持与v2.2.2中一致。选择类似css的属性名是为了给JavaScript开发者以最自然的开发体验。

2. cc.Node的attr函数

新API使得Cocos2d-JS代码更加简洁,但这还不够,我们为cc.Node添加了更为简单易用的attr函数。与jQuery的attr函数相同,这个函数允许开发者批量设置多个属性。示例如下:

node.attr({
    x: 20,
    y: 20,
    anchorX: 0.5,
    anchorY: 0.5,
    width: 400,
    height: 300,
    scale: 2
});

值得一提的是,这个函数不仅仅支持文末列表中的属性,也支持开发者的自定义属性。

3. 改变的初衷

为什么Cocos2d-JS要对已稳定的API做出如此大的改变呢?我想最显而易见的答案已经体现在前面的示例中了:那就是更简单。

但是我们真正想改变的目标,并不仅仅是更简单而已,或者说简单并不是目标,而是结果。长期以来,Cocos2d-JS一直被WEB开发者诟病其复杂程度导致难于学习和使用。在与其他html5游戏引擎比较之后,我们发现我们引擎最大的问题是,它并不是为JavaScript开发者设计的。事实上确实如此,到目前为止,Cocos2d-JS引擎的实现目标一直是尽力与Cocos2d-x的API保持一致,而Cocos2d-x是为C++开发者设计的,与此同时,Cocos2d家族的起源Cocos2d-iPhone也在引擎中留下了非常多objective-C风格的API设计。很显然,正是由于这些API被直接移植到h5引擎中,JavaScript开发者才会觉得引擎非常复杂难用。

所以引擎3.0版本的主要目标就是提供给开发者一套全新的JavaScript风格API,开发团队决定冒着很大的风险推动这次重构。

回到属性风格API,cc.Node以及所有继承自cc.Node的类都使用属性风格重构。以往的大多数getXXX()setXXX(value)都被直接属性存取取代了。同时也有也有少数其他适合属性风格的类使用这种方式重构,它们都可以在文末的列表中找到。

4. 关于Closure Compiler

由于attr函数使用键值对来配置节点,当我们使用Closure Compiler的高级模式来混淆时,这可能会引起一些意想不到的错误。

简单来说,键值对中的键实质上是String类型,混淆过程中它并不会被压缩,而与之相对应的属性名却会被压缩,这导致了两者命名的不匹配。所幸,在引擎中我们保障了常用的属性不会被压缩,至于其他的属性和用户自定义属性,可以使用Closure Compiler的expose声明来避免出现问题。需要注意的是这个问题只有在开发者尝试使用attr函数来配置属性的时候才会出现,如果没有使用attr函数就不需要做任何额外的处理。

/** @expose */
node.shaderProgram;

/** @expose */
node.customProperty;

node.attr({
    shaderProgram: program,
    customProperty: 0
});

5. 通过继承来重载属性

另一个重要的问题是在继承过程中,如何重载父类中的属性。好消息是我们已经将这一机制在Cocos2d-JS的cc.Class中实现了。只要你重载了父类中的getter/setter函数,那么不需要重新定义,新的getter/setter会自动被绑定到属性上。下面是一个重载Sprite类中的x属性的例子:

var MySprite = cc.Sprite.extend({
    ctor: function() {
        this._super();
        this.init();
    },
    getPositionX: function() {
        // Your own implementation
    },
    setPositionX: function(x) {
        // Your own implementation
    }
});

var mySprite = new MySprite();

mySprite.x = x;会调用MySprite类的setPositionX函数而不是Sprite类的,getter函数也是同理。用户代码中唯一需要保证的是重载的getter/setter函数名必须和父类中定义的属性的getter/setter函数同名。否则你将需要通过cc.defineGetterSetter重新定义属性。

6. 属性列表

cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
xNumberR&WgetPositionX, setPositionXYES
yNumberR&WgetPositionY, setPositionYYES
widthNumberR&W_getWidth, _setWidthYES
heightNumberR&W_getHeight, _setHeightYES
anchorXNumberR&W_getAnchorX, _setAnchorXYES
anchorYNumberR&W_getAnchorY, _setAnchorYYES
skewXNumberR&WgetSkewX, setSkewXYES
skewYNumberR&WgetSkewY, setSkewYYES
zIndexNumberR&WgetLocalZOrder, setLocalZOrderYES
vertexZNumberR&WgetVertexZ, setVertexZYES
rotationNumberR&WgetRotation, setRotationYES
rotationXNumberR&WgetRotationX, setRotationXYES
rotationYNumberR&WgetRotationY, setRotationYYES
scaleNumberR&WgetScale, setScaleYES
scaleXNumberR&WgetScaleX, setScaleXYES
scaleYNumberR&WgetScaleY, setScaleYYES
opacityNumberR&WgetOpacity, setOpacityYES
opacityModifyRGBBooleanR&WisOpacityModifyRGB, setOpacityModifyRGBYES
cascadeOpacityBooleanR&WisCascadeOpacityEnabled, setCascadeOpacityEnabledYES
colorcc.ColorR&WgetColor, setColorYES
cascadeColorBooleanR&WisCascadeColorEnabled, setCascadeColorEnabledYES
childrenArrayreadonlygetChildrenYES
childrenCountNumberreadonlygetChildrenCountYES
parentcc.NodeR&WgetParent, setParentYES
visibleBooleanR&WisVisible, setVisibleYES
runningBooleanreadonlyisRunningYES
ignoreAnchorBooleanR&WisIgnoreAnchorPointForPosition, ignoreAnchorPointForPositionYES
tagNumberR&WNoneYES
userDataObjectR&WNoneYES
userObjectObjectR&WNoneYES
arrivalOrderNumberR&WNoneYES
actionManagercc.ActionManagerR&WgetActionManager, setActionManagerYES
schedulercc.SchedulerR&WgetScheduler, setSchedulerYES
gridcc.GridBaseR&WNoneNO
shaderProgramcc.GLProgramR&WgetShaderProgram, setShaderProgramYES

cc.Texture2D

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
nameWebGLTexturereadonlygetNameNO
pixelFormatNumberreadonlygetPixelFormatNO
pixelsWidthNumberreadonlygetPixelsWideNO
pixelsHeightNumberreadonlygetPixelsHighNO
widthNumberR&W_getWidth, _setWidthNO
heightNumberR&W_getHeight, _setHeightNO
shaderProgramcc.GLProgramR&WNoneNO
maxSNumberR&WNoneNO
maxTNumberR&WNoneNO

cc.Sprite

Extend from cc.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
dirtyBooleanR&WNoneYES
flippedXBooleanR&WisFlippedX, setFlippedXYES
flippedYBooleanR&WisFlippedY, setFlippedYYES
offsetXNumberreadonly_getOffsetXYES
offsetYNumberreadonly_getOffsetYYES
atlasIndexNumberR&WNoneYES
texturecc.Texture2DR&WgetTexture, setTextureYES
textureRectRotatedBooleanreadonlyisTextureRectRotatedYES
textureAtlascc.TextureAtlasR&WNoneYES
batchNodecc.SpriteBatchNodeR&WgetBatchNode, setBatchNodeYES
quadcc.V3F_C4B_T2F_QuadreadonlygetQuadYES

cc.LabelTTF

Extend from cc.Sprite

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stringStringR&WgetString, setStringYES
textAlignNumberR&WgetHorizontalAlignment, setHorizontalAlignmentYES
verticalAlignNumberR&WgetVerticalAlignment, setVerticalAlignmentYES
fontSizeNumberR&WgetFontSize, setFontSizeYES
fontNameStringR&WgetFontName, setFontNameYES
fontStringR&W_getFont, _setFontYES
boundingWidthNumberR&W_getBoundingWidth, _setBoundingWidthYES
boundingHeightNumberR&W_getBoundingHeight, _setBoundingHeightYES
fillStylecc.ColorR&W_getFillStyle, setFontFillColorYES
strokeStylecc.ColorR&W_getStrokeStyle, _setStrokeStyleYES
lineWidthNumberR&W_getLineWidth, _setLineWidthYES
shadowOffsetXNumberR&W_getShadowOffsetX, _setShadowOffsetXYES
shadowOffsetYNumberR&W_getShadowOffsetY, _setShadowOffsetYYES
shadowOpacityNumberR&W_getShadowOpacity, _setShadowOpacityYES
shadowBlurNumberR&W_getShadowBlur, _setShadowBlurYES

cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
xNumberR&WgetPositionX, setPositionXYES
yNumberR&WgetPositionY, setPositionYYES
widthNumberR&W_getWidth, _setWidthYES
heightNumberR&W_getHeight, _setHeightYES
anchorXNumberR&W_getAnchorX, _setAnchorXYES
anchorYNumberR&W_getAnchorY, _setAnchorYYES
skewXNumberR&WgetSkewX, setSkewXYES
skewYNumberR&WgetSkewY, setSkewYYES
zIndexNumberR&WgetLocalZOrder, setLocalZOrderYES
vertexZNumberR&WgetVertexZ, setVertexZYES
rotationNumberR&WgetRotation, setRotationYES
rotationXNumberR&WgetRotationX, setRotationXYES
rotationYNumberR&WgetRotationY, setRotationYYES
scaleNumberR&WgetScale, setScaleYES
scaleXNumberR&WgetScaleX, setScaleXYES
scaleYNumberR&WgetScaleY, setScaleYYES
opacityNumberR&WgetOpacity, setOpacityYES
opacityModifyRGBBooleanR&WisOpacityModifyRGB, setOpacityModifyRGBYES
cascadeOpacityBooleanR&WisCascadeOpacityEnabled, setCascadeOpacityEnabledYES
colorcc.ColorR&WgetColor, setColorYES
cascadeColorBooleanR&WisCascadeColorEnabled, setCascadeColorEnabledYES
childrenArrayreadonlygetChildrenYES
childrenCountNumberreadonlygetChildrenCountYES
parentcc.NodeR&WgetParent, setParentYES
visibleBooleanR&WisVisible, setVisibleYES
runningBooleanreadonlyisRunningYES
ignoreAnchorBooleanR&WisIgnoreAnchorPointForPosition, ignoreAnchorPointForPositionYES
tagNumberR&WNoneYES
userDataObjectR&WNoneYES
userObjectObjectR&WNoneYES
arrivalOrderNumberR&WNoneYES
actionManagercc.ActionManagerR&WgetActionManager, setActionManagerYES
schedulercc.SchedulerR&WgetScheduler, setSchedulerYES
gridcc.GridBaseR&WNoneNO
shaderProgramcc.GLProgramR&WgetShaderProgram, setShaderProgramYES

cc.Texture2D

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
nameWebGLTexturereadonlygetNameNO
pixelFormatNumberreadonlygetPixelFormatNO
pixelsWidthNumberreadonlygetPixelsWideNO
pixelsHeightNumberreadonlygetPixelsHighNO
widthNumberR&W_getWidth, _setWidthNO
heightNumberR&W_getHeight, _setHeightNO
shaderProgramcc.GLProgramR&WNoneNO
maxSNumberR&WNoneNO
maxTNumberR&WNoneNO

cc.TextureAtlas

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
dirtyBooleanR&WNoneNO
textureImageR&WNoneNO
capacityNumberreadonlygetCapacityNO
totalQuadsNumberreadonlygetTotalQuadsNO
quadsArrayreadonlygetQuads, setQuadsNO

cc.AtlasNode

Extend from cc.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
texturecc.Texture2DR&WgetTexture, setTextureYES
textureAtlascc.TextureAtlasR&WNoneYES
quadsToDrawNumberR&WNoneYES

cc.LayerRGBA

Extend from cc.Layer

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
opacityModifyRGBBooleanR&WisOpacityModifyRGB, setOpacityModifyRGBYES
opacityNumberR&WgetOpacity, setOpacityYES
cascadeOpacityBooleanR&WisCascadeOpacityEnabled, setCascadeOpacityEnabledYES
colorcc.ColorR&WgetColor, setColorYES
cascadeColorBooleanR&WisCascadeColorEnabled, setCascadeColorEnabledYES

cc.LayerGradient

Extend from cc.LayerColor

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
startColorcc.ColorR&WgetStartColor, setStartColorYES
endColorcc.ColorR&WgetEndColor, setEndColorYES
startOpacityNumberR&WgetStartOpacity, setStartOpacityYES
endOpacityNumberR&WgetEndOpacity, setEndOpacityYES
vectorNumberR&WgetVector, setVectorYES
compresseInterpolationNumberR&WNoneNO

cc.ClippingNode

Extend from cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
alphaThresholdNumberR&WNoneNO
invertedBooleanR&WNoneNO
stencilcc.NodeR&WgetStencil, setStencilYES

cc.SpriteBatchNode

Extend from cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
textureAtlascc.TextureAtlasR&WNoneNO
descendantsArrayreadonlygetDescendantsNO

cc.Sprite

Extend from cc.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
dirtyBooleanR&WNoneYES
flippedXBooleanR&WisFlippedX, setFlippedXYES
flippedYBooleanR&WisFlippedY, setFlippedYYES
offsetXNumberreadonly_getOffsetXYES
offsetYNumberreadonly_getOffsetYYES
atlasIndexNumberR&WNoneYES
texturecc.Texture2DR&WgetTexture, setTextureYES
textureRectRotatedBooleanreadonlyisTextureRectRotatedYES
textureAtlascc.TextureAtlasR&WNoneYES
batchNodecc.SpriteBatchNodeR&WgetBatchNode, setBatchNodeYES
quadcc.V3F_C4B_T2F_QuadreadonlygetQuadYES

cc.LabelTTF

Extend from cc.Sprite

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stringStringR&WgetString, setStringYES
textAlignNumberR&WgetHorizontalAlignment, setHorizontalAlignmentYES
verticalAlignNumberR&WgetVerticalAlignment, setVerticalAlignmentYES
fontSizeNumberR&WgetFontSize, setFontSizeYES
fontNameStringR&WgetFontName, setFontNameYES
fontStringR&W_getFont, _setFontYES
boundingWidthNumberR&W_getBoundingWidth, _setBoundingWidthYES
boundingHeightNumberR&W_getBoundingHeight, _setBoundingHeightYES
fillStylecc.ColorR&W_getFillStyle, setFontFillColorYES
strokeStylecc.ColorR&W_getStrokeStyle, _setStrokeStyleYES
lineWidthNumberR&W_getLineWidth, _setLineWidthYES
shadowOffsetXNumberR&W_getShadowOffsetX, _setShadowOffsetXYES
shadowOffsetYNumberR&W_getShadowOffsetY, _setShadowOffsetYYES
shadowOpacityNumberR&W_getShadowOpacity, _setShadowOpacityYES
shadowBlurNumberR&W_getShadowBlur, _setShadowBlurYES

cc.LabelAtlas

Extend from cc.AtlasNode

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stringStringR&WgetString, setStringYES

cc.LabelBMFont

Extend from cc.SpriteBatchNode

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stringStringR&WgetString, _setStringForSetterYES
textAlignenumR&W_getAlignment, setAlignmentYES
boundingWidthNumberR&W_getBoundingWidth, setBoundingWidthYES
opacityModifyRGBBooleanR&WisOpacityModifyRGB, setOpacityModifyRGBYES
opacityNumberR&WgetOpacity, setOpacityYES
cascadeOpacityBooleanR&WisCascadeOpacityEnabled, setCascadeOpacityEnabledYES
colorcc.ColorR&WgetColor, setColorYES
cascadeColorBooleanR&WisCascadeColorEnabled, setCascadeColorEnabledYES

cc.Menu

Extend from cc.LayerRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
enabledBooleanR&WNoneYES

cc.MenuItem

Extend from cc.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
enabledBooleanR&WisEnabled, setEnabledYES

cc.MenuItemLabel

Extend from cc.MenuItem

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stringStringR&WgetString, setStringYES
labelcc.NodeR&WgetLabel, setLabelYES
disabledColorcc.ColorR&WgetDisabledColor, setDisabledColorYES

cc.MenuItemFont

Extend from cc.MenuItemLabel

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
fontSizeNumberR&WgetFontSize, setFontSizeYES
fontNameStringR&WgetFontName, setFontNameYES

cc.MenuItemSprite

Extend from cc.MenuItem

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
normalImagecc.SpriteR&WgetNormalImage, setNormalImageYES
selectedImagecc.SpriteR&WgetSelectedImage, setSelectedImageYES
disabledImagecc.SpriteR&WgetDisabledImage, setDisabledImageYES

cc.NodeGrid

Extend from cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
gridcc.GridBaseR&WNoneYES
targetcc.NodewriteonlysetTargetYES

cc.ParticleBatchNode

Extend from cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
textureAtlascc.TextureAtlasR&WNoneNO
texturecc.Texture2DR&WgetTexture, setTextureYES

cc.ParticleSystem

Extend from cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
opacityModifyRGBBooleanR&WisOpacityModifyRGB, setOpacityModifyRGBYES
batchNodecc.SpriteBatchNodeR&WgetBatchNode, setBatchNodeYES
activeBooleanreadonlyisActiveYES
shapeTypeNumberR&WNoneNO
atlasIndexNumberR&WNoneNO
particleCountNumberR&WNoneNO
durationNumberR&WNoneNO
sourcePoscc.PointR&WgetSourcePosition, setSourcePositionYES
posVarcc.PointR&WgetPosVar, setPosVarYES
lifeNumberR&WNoneNO
lifeVarNumberR&WNoneNO
angleNumberR&WNoneNO
angleVarNumberR&WNoneNO
startSizeNumberR&WNoneNO
startSizeVarNumberR&WNoneNO
endSizeNumberR&WNoneNO
endSizeVarNumberR&WNoneNO
startSpinNumberR&WNoneNO
startSpinVarNumberR&WNoneNO
endSpinNumberR&WNoneNO
endSpinVarNumberR&WNoneNO
gravitycc.PointR&WgetGravity, setGravityYES
speedcc.PointR&WgetSpeed, setSpeedYES
speedVarcc.PointR&WgetSpeedVar, setSpeedVarYES
tangentialAccelNumberR&WNoneNO
tangentialAccelVarNumberR&WNoneNO
tangentialAccelNumberR&WgetTangentialAccel, setTangentialAccelYES
tangentialAccelVarNumberR&WgetTangentialAccelVar, setTangentialAccelVarYES
rotationIsDirBooleanR&WgetRotationIsDir, setRotationIsDirYES
startRadiusNumberR&WgetStartRadius, setStartRadiusYES
startRadiusVarNumberR&WgetStartRadiusVar, setStartRadiusVarYES
endRadiusNumberR&WgetEndRadius, setEndRadiusYES
endRadiusVarNumberR&WgetEndRadiusVar, setEndRadiusVarYES
rotatePerSNumberR&WgetRotatePerSecond, setRotatePerSecondYES
rotatePerSVarNumberR&WgetRotatePerSecondVar, setRotatePerSecondVarYES
startColorcc.ColorR&WgetStartColor, setStartColorYES
startColorVarcc.ColorR&WgetStartColorVar, setStartColorVarYES
endColorcc.ColorR&WgetEndColor, setEndColorYES
endColorVarcc.ColorR&WgetEndColorVar, setEndColorVarYES
emissionRateNumberR&WNoneNO
emitterModeNumberR&WNoneNO
positionTypeNumberR&WNoneNO
totalParticlesNumberR&WgetTotalParticles, setTotalParticlesYES
autoRemoveOnFinishBooleanR&WNoneNO
texturecc.Texture2DR&WgetTexture, setTextureYES

cc.ProgressTimer

Extend from cc.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
midPointcc.PointR&WgetMidpoint, setMidpointYES
barChangeRatecc.PointR&WgetBarChangeRate, setBarChangeRateYES
typeenumR&WgetType, setTypeYES
percentageNumberR&WgetPercentage, setPercentageYES
spritecc.SpriteR&WgetSprite, setSpriteYES
reverseDirBooleanR&WisReverseDirection, setReverseDirectionYES

cc.RenderTexture

Extend from cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
spritecc.SpriteR&WNoneNO
clearFlagsNumberR&WNoneNO
clearDepthValNumberR&WNoneNO
clearStencilValNumberR&WNoneNO
clearColorValcc.ColorR&WgetClearColor, setClearColorNO
autoDrawBooleanR&WNoneNO

cc.TMXLayer

Extend from cc.SpriteBatchNode

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
tilesArrayR&WNoneNO
tilesetcc.TMXTilesetInfoR&WNoneNO
layerOrientationNumberR&WNoneNO
propertiesArrayR&WNoneNO
layerNameStringR&WNoneNO
layerWidthNumberR&W_getLayerWidth, _setLayerWidthNO
layerHeightNumberR&W_getLayerHeight, _setLayerHeightNO
tileWidthNumberR&W_getTileWidth, _setTileWidthNO
tileHeightNumberR&W_getTileHeight, _setTileHeightNO

cc.TMXTiledMap

Extend from cc.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
propertiesArrayR&WNoneNO
mapOrientationNumberR&WNoneNO
objectGroupsArrayR&WNoneNO
mapWidthNumberR&W_getMapWidth, _setMapWidthNO
mapHeightNumberR&W_getMapHeight, _setMapHeightNO
tileWidthNumberR&W_getTileWidth, _setTileWidthNO
tileHeightNumberR&W_getTileHeight, _setTileHeightNO

ccui.Widget

Extend from ccui.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
xPercentNumberR&W_getXPercent, _setXPercentYES
yPercentNumberR&W_getYPercent, _setYPercentYES
widthPercentNumberR&W_getWidthPercent, _setWidthPercentYES
heightPercentNumberR&W_getHeightPercent, _setHeightPercentYES
widgetParentccui.WidgetreadonlygetWidgetParentYES
enabledBooleanR&WisEnabled, setEnabledYES
focusedBooleanR&WisFocused, setFocusedYES
touchEnabledBooleanR&WisTouchEnabled, setTouchEnabledYES
updateEnabledBooleanR&WisUpdateEnabled, setUpdateEnabledYES
brightBooleanR&WisBright, setBrightYES
nameStringR&WgetName, setNameYES
actionTagNumberR&WgetActionTag, setActionTagYES

ccui.Layout

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
clippingEnabledBooleanR&WisClippingEnabled, setClippingEnabledYES

ccui.Button

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
titleTextStringR&WgetTitleText, setTitleTextYES
titleFontStringR&W_getTitleFont, _setTitleFontYES
titleFontSizeNumberR&WgetTitleFontSize, setTitleFontSizeYES
titleFontNameStringR&WgetTitleFontName, setTitleFontNameYES
titleFontColorcc.ColorR&WNoneNO
pressedActionEnabledBooleanR&WNoneNO

ccui.CheckBox

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
selectedBooleanR&WgetSelectedState, setSelectedStateYES

ccui.LoadingBar

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
percentNumberR&WgetPercent, setPercentYES

ccui.Slider

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
percentNumberR&WgetPercent, setPercentYES

ccui.Text

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
boundingWidthNumberR&W_getBoundingWidth, _setBoundingWidthYES
boundingHeightNumberR&W_getBoundingHeight, _setBoundingHeightYES
stringStringR&WgetStringValue, setTextYES
stringLengthNumberreadonlygetStringLengthYES
fontStringR&W_getFont, _setFontYES
fontNameStringR&WgetFontName, setFontNameYES
fontSizeNumberR&WgetFontSize, setFontSizeYES
textAlignNumberR&WgetTextHorizontalAlignment, setTextHorizontalAlignmentYES
verticalAlignNumberR&WgetTextVerticalAlignment, setTextVerticalAlignmentYES
touchScaleEnabledBooleanR&WNoneNO

ccui.TextAtlas

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stringStringR&WgetStringValue, setStringValueYES

ccui.TextBMFont

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stringStringR&WgetStringValue, setStringValueYES

ccui.TextField

Extend from ccui.Widget

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
maxLengthEnabledBooleanR&WisMaxLengthEnabled, setMaxLengthEnabledYES
maxLengthNumberR&WgetMaxLength, setMaxLengthYES
passwordEnabledBooleanR&WisPasswordEnabled, setPasswordEnabledYES
stringStringR&WgetStringValue, setTextYES
fontStringR&W_getFont, _setFontYES
fontSizeNumberR&WgetFontSize, setFontSizeYES
fontNameStringR&WgetFontName, setFontNameYES

ccui.ScrollView

Extend from ccui.Layout

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
innerWidthNumberR&W_getInnerWidth, _setInnerWidthYES
innerHeightNumberR&W_getInnerHeight, _setInnerHeightYES
bounceEnabledBooleanR&WNoneNO
inertiaScrollEnabledBooleanR&WNoneNO

ccs.Armature

Extend from ccs.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
parentBoneccs.BoneR&WgetParentBone, setParentBoneYES
animationccs.ArmatureAnimationR&WNoneNO
armatureDataccs.ArmatureDataR&WNoneNO
nameStringR&WNoneNO
batchNodecc.SpriteBatchNodeR&WNoneNO
versionNumberR&WNoneNO
bodyObjectR&WgetBody, setBodyYES
colliderFilterccs.ColliderFilterwriteonlysetColliderFilterYES

ccs.Bone

Extend from ccs.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
boneDataccs.BoneDataR&WgetBoneData, setBoneDataYES
armatureccs.ArmatureR&WgetArmature, setArmatureYES
parentBoneccs.BoneR&WNoneNO
childArmatureccs.ArmatureR&WgetChildArmature, setChildArmatureYES
childrenBoneArrayreadonlygetChildrenBoneYES
tweenccs.TweenreadonlygetTweenYES
tweenDataccs.FrameDatareadonlygetTweenDataYES
transformDirtyBooleanR&WNoneNO
colliderFilterccs.ColliderFilterR&WgetColliderFilter, setColliderFilterYES
displayManagerccs.DisplayManagerR&WNoneNO
ignoreMovementBoneDataBooleanR&WNoneNO
nameStringR&WNoneNO
blendDirtyBooleanR&WNoneNO

ccs.Skin

Extend from ccs.Sprite

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
skinDataObjectR&WgetSkinData, setSkinDataYES
boneccs.BoneR&WNoneNO
displayNameStringreadonlygetDisplayNameYES

cc.EditBox

Extend from cc.ControlButton

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
fontStringR&W_setFontYES
fontNameStringR&WsetFontNameYES
fontSizeNumberR&WsetFontSizeYES
stringStringR&WgetText, setTextYES
maxLengthNumberR&WgetMaxLength, setMaxLengthYES

cc.Control

Extend from cc.LayerRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
stateNumberreadonlygetStateYES
enabledBooleanR&WisEnabled, setEnabledYES
selectedBooleanR&WisSelected, setSelectedYES
highlightedBooleanR&WisHighlighted, setHighlightedYES

cc.ControlButton

Extend from cc.Control

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
adjustBackgroundImageBooleanR&WNoneNO
zoomOnTouchDownBooleanR&WNoneNO
preferredSizecc.SizeR&WgetPreferredSize, setPreferredSizeYES
labelAnchorBooleanR&WgetLabelAnchorPoint, setLabelAnchorPointYES

cc.ControlColourPicker

Extend from cc.Control

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
backgroundcc.SpritereadonlygetBackgroundYES

cc.ControlHuePicker

Extend from cc.Control

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
hueNumberR&WgetHue, setHueYES
huePercentNumberR&WgetHuePercentage, setHuePercentageYES
backgroundcc.SpritereadonlygetBackgroundYES
slidercc.SpritereadonlygetSliderYES
startPoscc.PointreadonlygetStartPosYES

cc.ControlPotentiometer

Extend from cc.Control

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
valueNumberR&WgetValue, setValueYES
minValueNumberR&WgetMinimumValue, setMinimumValueYES
maxValueNumberR&WgetMaximumValue, setMaximumValueYES
progressTimercc.ProgressTimerR&WgetProgressTimer, setProgressTimerYES
thumbSpritecc.SpriteR&WgetThumbSprite, setThumbSpriteYES
prevLocationcc.PointR&WgetPreviousLocation, setPreviousLocationYES

cc.ControlSaturationBrightnessPicker

Extend from cc.Control

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
saturationNumberreadonlygetSaturationYES
brightnessNumberreadonlygetBrightnessYES
backgroundcc.SpritereadonlygetBackgroundYES
overlaycc.SpritereadonlygetOverlayYES
shadowcc.SpritereadonlygetShadowYES
slidercc.SpritereadonlygetSliderYES
startPoscc.PointreadonlygetStartPosYES

cc.ControlSlider

Extend from cc.Control

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
valueNumberR&WgetValue, setValueYES
minValueNumberR&WgetMinimumValue, setMinimumValueYES
maxValueNumberR&WgetMaximumValue, setMaximumValueYES
minAllowedValueNumberR&WgetMinimumAllowedValue, setMinimumAllowedValueYES
maxAllowedValueNumberR&WgetMaximumAllowedValue, setMaximumAllowedValueYES
thumbSpriteNumberreadonlygetThumbSpriteYES
progressSpritecc.SpritereadonlygetProgressSpriteYES
backgroundSpritecc.SpritereadonlygetBackgroundSpriteYES

cc.ControlStepper

Extend from cc.Control

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
wrapsBooleanR&WgetWraps, setWrapsYES
valueNumberR&WgetValue, setValueYES
minValueNumberR&WgetMinimumValue, setMinimumValueYES
maxValueNumberR&WgetMaximumValue, setMaximumValueYES
stepValueNumberR&WgetStepValue, setStepValueYES
continuousBooleanreadonlyisContinuousYES
minusSpritecc.SpriteR&WgetMinusSprite, setMinusSpriteYES
plusSpritecc.SpriteR&WgetPlusSprite, setPlusSpriteYES
minusLabelcc.LabelTTFR&WgetMinusLabel, setMinusLabelYES
plusSLabelcc.LabelTTFR&WNoneNO

cc.Scale9Sprite

Extend from cc.NodeRGBA

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
preferredSizecc.SizeR&WgetPreferredSize, setPreferredSizeYES
capInsetscc.RectR&WgetCapInsets, setCapInsetsYES
insetLeftNumberR&WgetInsetLeft, setInsetLeftYES
insetTopNumberR&WgetInsetTop, setInsetTopYES
insetRightNumberR&WgetInsetRight, setInsetRightYES
insetBottomNumberR&WgetInsetBottom, setInsetBottomYES

cc.TableViewCell

Extend from cc.Node

PropertyTypeAccessibilityGetter/Setter functionAdvanced Compress Ready
objectIdNumberR&WgetObjectID, setObjectIDYES
转载请注明:http://www.cocos2dx.net/post/235

【cocos2d-js官方文档】十八、Cocos2d-JS v3.0中的属性风格API