【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

Property Type Accessibility Getter/Setter function Advanced Compress Ready
x Number R&W getPositionX, setPositionX YES
y Number R&W getPositionY, setPositionY YES
width Number R&W _getWidth, _setWidth YES
height Number R&W _getHeight, _setHeight YES
anchorX Number R&W _getAnchorX, _setAnchorX YES
anchorY Number R&W _getAnchorY, _setAnchorY YES
skewX Number R&W getSkewX, setSkewX YES
skewY Number R&W getSkewY, setSkewY YES
zIndex Number R&W getLocalZOrder, setLocalZOrder YES
vertexZ Number R&W getVertexZ, setVertexZ YES
rotation Number R&W getRotation, setRotation YES
rotationX Number R&W getRotationX, setRotationX YES
rotationY Number R&W getRotationY, setRotationY YES
scale Number R&W getScale, setScale YES
scaleX Number R&W getScaleX, setScaleX YES
scaleY Number R&W getScaleY, setScaleY YES
opacity Number R&W getOpacity, setOpacity YES
opacityModifyRGB Boolean R&W isOpacityModifyRGB, setOpacityModifyRGB YES
cascadeOpacity Boolean R&W isCascadeOpacityEnabled, setCascadeOpacityEnabled YES
color cc.Color R&W getColor, setColor YES
cascadeColor Boolean R&W isCascadeColorEnabled, setCascadeColorEnabled YES
children Array readonly getChildren YES
childrenCount Number readonly getChildrenCount YES
parent cc.Node R&W getParent, setParent YES
visible Boolean R&W isVisible, setVisible YES
running Boolean readonly isRunning YES
ignoreAnchor Boolean R&W isIgnoreAnchorPointForPosition, ignoreAnchorPointForPosition YES
tag Number R&W None YES
userData Object R&W None YES
userObject Object R&W None YES
arrivalOrder Number R&W None YES
actionManager cc.ActionManager R&W getActionManager, setActionManager YES
scheduler cc.Scheduler R&W getScheduler, setScheduler YES
grid cc.GridBase R&W None NO
shaderProgram cc.GLProgram R&W getShaderProgram, setShaderProgram YES

cc.Texture2D

Property Type Accessibility Getter/Setter function Advanced Compress Ready
name WebGLTexture readonly getName NO
pixelFormat Number readonly getPixelFormat NO
pixelsWidth Number readonly getPixelsWide NO
pixelsHeight Number readonly getPixelsHigh NO
width Number R&W _getWidth, _setWidth NO
height Number R&W _getHeight, _setHeight NO
shaderProgram cc.GLProgram R&W None NO
maxS Number R&W None NO
maxT Number R&W None NO

cc.Sprite

Extend from cc.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
dirty Boolean R&W None YES
flippedX Boolean R&W isFlippedX, setFlippedX YES
flippedY Boolean R&W isFlippedY, setFlippedY YES
offsetX Number readonly _getOffsetX YES
offsetY Number readonly _getOffsetY YES
atlasIndex Number R&W None YES
texture cc.Texture2D R&W getTexture, setTexture YES
textureRectRotated Boolean readonly isTextureRectRotated YES
textureAtlas cc.TextureAtlas R&W None YES
batchNode cc.SpriteBatchNode R&W getBatchNode, setBatchNode YES
quad cc.V3F_C4B_T2F_Quad readonly getQuad YES

cc.LabelTTF

Extend from cc.Sprite

Property Type Accessibility Getter/Setter function Advanced Compress Ready
string String R&W getString, setString YES
textAlign Number R&W getHorizontalAlignment, setHorizontalAlignment YES
verticalAlign Number R&W getVerticalAlignment, setVerticalAlignment YES
fontSize Number R&W getFontSize, setFontSize YES
fontName String R&W getFontName, setFontName YES
font String R&W _getFont, _setFont YES
boundingWidth Number R&W _getBoundingWidth, _setBoundingWidth YES
boundingHeight Number R&W _getBoundingHeight, _setBoundingHeight YES
fillStyle cc.Color R&W _getFillStyle, setFontFillColor YES
strokeStyle cc.Color R&W _getStrokeStyle, _setStrokeStyle YES
lineWidth Number R&W _getLineWidth, _setLineWidth YES
shadowOffsetX Number R&W _getShadowOffsetX, _setShadowOffsetX YES
shadowOffsetY Number R&W _getShadowOffsetY, _setShadowOffsetY YES
shadowOpacity Number R&W _getShadowOpacity, _setShadowOpacity YES
shadowBlur Number R&W _getShadowBlur, _setShadowBlur YES

cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
x Number R&W getPositionX, setPositionX YES
y Number R&W getPositionY, setPositionY YES
width Number R&W _getWidth, _setWidth YES
height Number R&W _getHeight, _setHeight YES
anchorX Number R&W _getAnchorX, _setAnchorX YES
anchorY Number R&W _getAnchorY, _setAnchorY YES
skewX Number R&W getSkewX, setSkewX YES
skewY Number R&W getSkewY, setSkewY YES
zIndex Number R&W getLocalZOrder, setLocalZOrder YES
vertexZ Number R&W getVertexZ, setVertexZ YES
rotation Number R&W getRotation, setRotation YES
rotationX Number R&W getRotationX, setRotationX YES
rotationY Number R&W getRotationY, setRotationY YES
scale Number R&W getScale, setScale YES
scaleX Number R&W getScaleX, setScaleX YES
scaleY Number R&W getScaleY, setScaleY YES
opacity Number R&W getOpacity, setOpacity YES
opacityModifyRGB Boolean R&W isOpacityModifyRGB, setOpacityModifyRGB YES
cascadeOpacity Boolean R&W isCascadeOpacityEnabled, setCascadeOpacityEnabled YES
color cc.Color R&W getColor, setColor YES
cascadeColor Boolean R&W isCascadeColorEnabled, setCascadeColorEnabled YES
children Array readonly getChildren YES
childrenCount Number readonly getChildrenCount YES
parent cc.Node R&W getParent, setParent YES
visible Boolean R&W isVisible, setVisible YES
running Boolean readonly isRunning YES
ignoreAnchor Boolean R&W isIgnoreAnchorPointForPosition, ignoreAnchorPointForPosition YES
tag Number R&W None YES
userData Object R&W None YES
userObject Object R&W None YES
arrivalOrder Number R&W None YES
actionManager cc.ActionManager R&W getActionManager, setActionManager YES
scheduler cc.Scheduler R&W getScheduler, setScheduler YES
grid cc.GridBase R&W None NO
shaderProgram cc.GLProgram R&W getShaderProgram, setShaderProgram YES

cc.Texture2D

Property Type Accessibility Getter/Setter function Advanced Compress Ready
name WebGLTexture readonly getName NO
pixelFormat Number readonly getPixelFormat NO
pixelsWidth Number readonly getPixelsWide NO
pixelsHeight Number readonly getPixelsHigh NO
width Number R&W _getWidth, _setWidth NO
height Number R&W _getHeight, _setHeight NO
shaderProgram cc.GLProgram R&W None NO
maxS Number R&W None NO
maxT Number R&W None NO

cc.TextureAtlas

Property Type Accessibility Getter/Setter function Advanced Compress Ready
dirty Boolean R&W None NO
texture Image R&W None NO
capacity Number readonly getCapacity NO
totalQuads Number readonly getTotalQuads NO
quads Array readonly getQuads, setQuads NO

cc.AtlasNode

Extend from cc.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
texture cc.Texture2D R&W getTexture, setTexture YES
textureAtlas cc.TextureAtlas R&W None YES
quadsToDraw Number R&W None YES

cc.LayerRGBA

Extend from cc.Layer

Property Type Accessibility Getter/Setter function Advanced Compress Ready
opacityModifyRGB Boolean R&W isOpacityModifyRGB, setOpacityModifyRGB YES
opacity Number R&W getOpacity, setOpacity YES
cascadeOpacity Boolean R&W isCascadeOpacityEnabled, setCascadeOpacityEnabled YES
color cc.Color R&W getColor, setColor YES
cascadeColor Boolean R&W isCascadeColorEnabled, setCascadeColorEnabled YES

cc.LayerGradient

Extend from cc.LayerColor

Property Type Accessibility Getter/Setter function Advanced Compress Ready
startColor cc.Color R&W getStartColor, setStartColor YES
endColor cc.Color R&W getEndColor, setEndColor YES
startOpacity Number R&W getStartOpacity, setStartOpacity YES
endOpacity Number R&W getEndOpacity, setEndOpacity YES
vector Number R&W getVector, setVector YES
compresseInterpolation Number R&W None NO

cc.ClippingNode

Extend from cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
alphaThreshold Number R&W None NO
inverted Boolean R&W None NO
stencil cc.Node R&W getStencil, setStencil YES

cc.SpriteBatchNode

Extend from cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
textureAtlas cc.TextureAtlas R&W None NO
descendants Array readonly getDescendants NO

cc.Sprite

Extend from cc.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
dirty Boolean R&W None YES
flippedX Boolean R&W isFlippedX, setFlippedX YES
flippedY Boolean R&W isFlippedY, setFlippedY YES
offsetX Number readonly _getOffsetX YES
offsetY Number readonly _getOffsetY YES
atlasIndex Number R&W None YES
texture cc.Texture2D R&W getTexture, setTexture YES
textureRectRotated Boolean readonly isTextureRectRotated YES
textureAtlas cc.TextureAtlas R&W None YES
batchNode cc.SpriteBatchNode R&W getBatchNode, setBatchNode YES
quad cc.V3F_C4B_T2F_Quad readonly getQuad YES

cc.LabelTTF

Extend from cc.Sprite

Property Type Accessibility Getter/Setter function Advanced Compress Ready
string String R&W getString, setString YES
textAlign Number R&W getHorizontalAlignment, setHorizontalAlignment YES
verticalAlign Number R&W getVerticalAlignment, setVerticalAlignment YES
fontSize Number R&W getFontSize, setFontSize YES
fontName String R&W getFontName, setFontName YES
font String R&W _getFont, _setFont YES
boundingWidth Number R&W _getBoundingWidth, _setBoundingWidth YES
boundingHeight Number R&W _getBoundingHeight, _setBoundingHeight YES
fillStyle cc.Color R&W _getFillStyle, setFontFillColor YES
strokeStyle cc.Color R&W _getStrokeStyle, _setStrokeStyle YES
lineWidth Number R&W _getLineWidth, _setLineWidth YES
shadowOffsetX Number R&W _getShadowOffsetX, _setShadowOffsetX YES
shadowOffsetY Number R&W _getShadowOffsetY, _setShadowOffsetY YES
shadowOpacity Number R&W _getShadowOpacity, _setShadowOpacity YES
shadowBlur Number R&W _getShadowBlur, _setShadowBlur YES

cc.LabelAtlas

Extend from cc.AtlasNode

Property Type Accessibility Getter/Setter function Advanced Compress Ready
string String R&W getString, setString YES

cc.LabelBMFont

Extend from cc.SpriteBatchNode

Property Type Accessibility Getter/Setter function Advanced Compress Ready
string String R&W getString, _setStringForSetter YES
textAlign enum R&W _getAlignment, setAlignment YES
boundingWidth Number R&W _getBoundingWidth, setBoundingWidth YES
opacityModifyRGB Boolean R&W isOpacityModifyRGB, setOpacityModifyRGB YES
opacity Number R&W getOpacity, setOpacity YES
cascadeOpacity Boolean R&W isCascadeOpacityEnabled, setCascadeOpacityEnabled YES
color cc.Color R&W getColor, setColor YES
cascadeColor Boolean R&W isCascadeColorEnabled, setCascadeColorEnabled YES

cc.Menu

Extend from cc.LayerRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
enabled Boolean R&W None YES

cc.MenuItem

Extend from cc.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
enabled Boolean R&W isEnabled, setEnabled YES

cc.MenuItemLabel

Extend from cc.MenuItem

Property Type Accessibility Getter/Setter function Advanced Compress Ready
string String R&W getString, setString YES
label cc.Node R&W getLabel, setLabel YES
disabledColor cc.Color R&W getDisabledColor, setDisabledColor YES

cc.MenuItemFont

Extend from cc.MenuItemLabel

Property Type Accessibility Getter/Setter function Advanced Compress Ready
fontSize Number R&W getFontSize, setFontSize YES
fontName String R&W getFontName, setFontName YES

cc.MenuItemSprite

Extend from cc.MenuItem

Property Type Accessibility Getter/Setter function Advanced Compress Ready
normalImage cc.Sprite R&W getNormalImage, setNormalImage YES
selectedImage cc.Sprite R&W getSelectedImage, setSelectedImage YES
disabledImage cc.Sprite R&W getDisabledImage, setDisabledImage YES

cc.NodeGrid

Extend from cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
grid cc.GridBase R&W None YES
target cc.Node writeonly setTarget YES

cc.ParticleBatchNode

Extend from cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
textureAtlas cc.TextureAtlas R&W None NO
texture cc.Texture2D R&W getTexture, setTexture YES

cc.ParticleSystem

Extend from cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
opacityModifyRGB Boolean R&W isOpacityModifyRGB, setOpacityModifyRGB YES
batchNode cc.SpriteBatchNode R&W getBatchNode, setBatchNode YES
active Boolean readonly isActive YES
shapeType Number R&W None NO
atlasIndex Number R&W None NO
particleCount Number R&W None NO
duration Number R&W None NO
sourcePos cc.Point R&W getSourcePosition, setSourcePosition YES
posVar cc.Point R&W getPosVar, setPosVar YES
life Number R&W None NO
lifeVar Number R&W None NO
angle Number R&W None NO
angleVar Number R&W None NO
startSize Number R&W None NO
startSizeVar Number R&W None NO
endSize Number R&W None NO
endSizeVar Number R&W None NO
startSpin Number R&W None NO
startSpinVar Number R&W None NO
endSpin Number R&W None NO
endSpinVar Number R&W None NO
gravity cc.Point R&W getGravity, setGravity YES
speed cc.Point R&W getSpeed, setSpeed YES
speedVar cc.Point R&W getSpeedVar, setSpeedVar YES
tangentialAccel Number R&W None NO
tangentialAccelVar Number R&W None NO
tangentialAccel Number R&W getTangentialAccel, setTangentialAccel YES
tangentialAccelVar Number R&W getTangentialAccelVar, setTangentialAccelVar YES
rotationIsDir Boolean R&W getRotationIsDir, setRotationIsDir YES
startRadius Number R&W getStartRadius, setStartRadius YES
startRadiusVar Number R&W getStartRadiusVar, setStartRadiusVar YES
endRadius Number R&W getEndRadius, setEndRadius YES
endRadiusVar Number R&W getEndRadiusVar, setEndRadiusVar YES
rotatePerS Number R&W getRotatePerSecond, setRotatePerSecond YES
rotatePerSVar Number R&W getRotatePerSecondVar, setRotatePerSecondVar YES
startColor cc.Color R&W getStartColor, setStartColor YES
startColorVar cc.Color R&W getStartColorVar, setStartColorVar YES
endColor cc.Color R&W getEndColor, setEndColor YES
endColorVar cc.Color R&W getEndColorVar, setEndColorVar YES
emissionRate Number R&W None NO
emitterMode Number R&W None NO
positionType Number R&W None NO
totalParticles Number R&W getTotalParticles, setTotalParticles YES
autoRemoveOnFinish Boolean R&W None NO
texture cc.Texture2D R&W getTexture, setTexture YES

cc.ProgressTimer

Extend from cc.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
midPoint cc.Point R&W getMidpoint, setMidpoint YES
barChangeRate cc.Point R&W getBarChangeRate, setBarChangeRate YES
type enum R&W getType, setType YES
percentage Number R&W getPercentage, setPercentage YES
sprite cc.Sprite R&W getSprite, setSprite YES
reverseDir Boolean R&W isReverseDirection, setReverseDirection YES

cc.RenderTexture

Extend from cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
sprite cc.Sprite R&W None NO
clearFlags Number R&W None NO
clearDepthVal Number R&W None NO
clearStencilVal Number R&W None NO
clearColorVal cc.Color R&W getClearColor, setClearColor NO
autoDraw Boolean R&W None NO

cc.TMXLayer

Extend from cc.SpriteBatchNode

Property Type Accessibility Getter/Setter function Advanced Compress Ready
tiles Array R&W None NO
tileset cc.TMXTilesetInfo R&W None NO
layerOrientation Number R&W None NO
properties Array R&W None NO
layerName String R&W None NO
layerWidth Number R&W _getLayerWidth, _setLayerWidth NO
layerHeight Number R&W _getLayerHeight, _setLayerHeight NO
tileWidth Number R&W _getTileWidth, _setTileWidth NO
tileHeight Number R&W _getTileHeight, _setTileHeight NO

cc.TMXTiledMap

Extend from cc.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
properties Array R&W None NO
mapOrientation Number R&W None NO
objectGroups Array R&W None NO
mapWidth Number R&W _getMapWidth, _setMapWidth NO
mapHeight Number R&W _getMapHeight, _setMapHeight NO
tileWidth Number R&W _getTileWidth, _setTileWidth NO
tileHeight Number R&W _getTileHeight, _setTileHeight NO

ccui.Widget

Extend from ccui.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
xPercent Number R&W _getXPercent, _setXPercent YES
yPercent Number R&W _getYPercent, _setYPercent YES
widthPercent Number R&W _getWidthPercent, _setWidthPercent YES
heightPercent Number R&W _getHeightPercent, _setHeightPercent YES
widgetParent ccui.Widget readonly getWidgetParent YES
enabled Boolean R&W isEnabled, setEnabled YES
focused Boolean R&W isFocused, setFocused YES
touchEnabled Boolean R&W isTouchEnabled, setTouchEnabled YES
updateEnabled Boolean R&W isUpdateEnabled, setUpdateEnabled YES
bright Boolean R&W isBright, setBright YES
name String R&W getName, setName YES
actionTag Number R&W getActionTag, setActionTag YES

ccui.Layout

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
clippingEnabled Boolean R&W isClippingEnabled, setClippingEnabled YES

ccui.Button

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
titleText String R&W getTitleText, setTitleText YES
titleFont String R&W _getTitleFont, _setTitleFont YES
titleFontSize Number R&W getTitleFontSize, setTitleFontSize YES
titleFontName String R&W getTitleFontName, setTitleFontName YES
titleFontColor cc.Color R&W None NO
pressedActionEnabled Boolean R&W None NO

ccui.CheckBox

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
selected Boolean R&W getSelectedState, setSelectedState YES

ccui.LoadingBar

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
percent Number R&W getPercent, setPercent YES

ccui.Slider

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
percent Number R&W getPercent, setPercent YES

ccui.Text

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
boundingWidth Number R&W _getBoundingWidth, _setBoundingWidth YES
boundingHeight Number R&W _getBoundingHeight, _setBoundingHeight YES
string String R&W getStringValue, setText YES
stringLength Number readonly getStringLength YES
font String R&W _getFont, _setFont YES
fontName String R&W getFontName, setFontName YES
fontSize Number R&W getFontSize, setFontSize YES
textAlign Number R&W getTextHorizontalAlignment, setTextHorizontalAlignment YES
verticalAlign Number R&W getTextVerticalAlignment, setTextVerticalAlignment YES
touchScaleEnabled Boolean R&W None NO

ccui.TextAtlas

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
string String R&W getStringValue, setStringValue YES

ccui.TextBMFont

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
string String R&W getStringValue, setStringValue YES

ccui.TextField

Extend from ccui.Widget

Property Type Accessibility Getter/Setter function Advanced Compress Ready
maxLengthEnabled Boolean R&W isMaxLengthEnabled, setMaxLengthEnabled YES
maxLength Number R&W getMaxLength, setMaxLength YES
passwordEnabled Boolean R&W isPasswordEnabled, setPasswordEnabled YES
string String R&W getStringValue, setText YES
font String R&W _getFont, _setFont YES
fontSize Number R&W getFontSize, setFontSize YES
fontName String R&W getFontName, setFontName YES

ccui.ScrollView

Extend from ccui.Layout

Property Type Accessibility Getter/Setter function Advanced Compress Ready
innerWidth Number R&W _getInnerWidth, _setInnerWidth YES
innerHeight Number R&W _getInnerHeight, _setInnerHeight YES
bounceEnabled Boolean R&W None NO
inertiaScrollEnabled Boolean R&W None NO

ccs.Armature

Extend from ccs.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
parentBone ccs.Bone R&W getParentBone, setParentBone YES
animation ccs.ArmatureAnimation R&W None NO
armatureData ccs.ArmatureData R&W None NO
name String R&W None NO
batchNode cc.SpriteBatchNode R&W None NO
version Number R&W None NO
body Object R&W getBody, setBody YES
colliderFilter ccs.ColliderFilter writeonly setColliderFilter YES

ccs.Bone

Extend from ccs.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
boneData ccs.BoneData R&W getBoneData, setBoneData YES
armature ccs.Armature R&W getArmature, setArmature YES
parentBone ccs.Bone R&W None NO
childArmature ccs.Armature R&W getChildArmature, setChildArmature YES
childrenBone Array readonly getChildrenBone YES
tween ccs.Tween readonly getTween YES
tweenData ccs.FrameData readonly getTweenData YES
transformDirty Boolean R&W None NO
colliderFilter ccs.ColliderFilter R&W getColliderFilter, setColliderFilter YES
displayManager ccs.DisplayManager R&W None NO
ignoreMovementBoneData Boolean R&W None NO
name String R&W None NO
blendDirty Boolean R&W None NO

ccs.Skin

Extend from ccs.Sprite

Property Type Accessibility Getter/Setter function Advanced Compress Ready
skinData Object R&W getSkinData, setSkinData YES
bone ccs.Bone R&W None NO
displayName String readonly getDisplayName YES

cc.EditBox

Extend from cc.ControlButton

Property Type Accessibility Getter/Setter function Advanced Compress Ready
font String R&W _setFont YES
fontName String R&W setFontName YES
fontSize Number R&W setFontSize YES
string String R&W getText, setText YES
maxLength Number R&W getMaxLength, setMaxLength YES

cc.Control

Extend from cc.LayerRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
state Number readonly getState YES
enabled Boolean R&W isEnabled, setEnabled YES
selected Boolean R&W isSelected, setSelected YES
highlighted Boolean R&W isHighlighted, setHighlighted YES

cc.ControlButton

Extend from cc.Control

Property Type Accessibility Getter/Setter function Advanced Compress Ready
adjustBackgroundImage Boolean R&W None NO
zoomOnTouchDown Boolean R&W None NO
preferredSize cc.Size R&W getPreferredSize, setPreferredSize YES
labelAnchor Boolean R&W getLabelAnchorPoint, setLabelAnchorPoint YES

cc.ControlColourPicker

Extend from cc.Control

Property Type Accessibility Getter/Setter function Advanced Compress Ready
background cc.Sprite readonly getBackground YES

cc.ControlHuePicker

Extend from cc.Control

Property Type Accessibility Getter/Setter function Advanced Compress Ready
hue Number R&W getHue, setHue YES
huePercent Number R&W getHuePercentage, setHuePercentage YES
background cc.Sprite readonly getBackground YES
slider cc.Sprite readonly getSlider YES
startPos cc.Point readonly getStartPos YES

cc.ControlPotentiometer

Extend from cc.Control

Property Type Accessibility Getter/Setter function Advanced Compress Ready
value Number R&W getValue, setValue YES
minValue Number R&W getMinimumValue, setMinimumValue YES
maxValue Number R&W getMaximumValue, setMaximumValue YES
progressTimer cc.ProgressTimer R&W getProgressTimer, setProgressTimer YES
thumbSprite cc.Sprite R&W getThumbSprite, setThumbSprite YES
prevLocation cc.Point R&W getPreviousLocation, setPreviousLocation YES

cc.ControlSaturationBrightnessPicker

Extend from cc.Control

Property Type Accessibility Getter/Setter function Advanced Compress Ready
saturation Number readonly getSaturation YES
brightness Number readonly getBrightness YES
background cc.Sprite readonly getBackground YES
overlay cc.Sprite readonly getOverlay YES
shadow cc.Sprite readonly getShadow YES
slider cc.Sprite readonly getSlider YES
startPos cc.Point readonly getStartPos YES

cc.ControlSlider

Extend from cc.Control

Property Type Accessibility Getter/Setter function Advanced Compress Ready
value Number R&W getValue, setValue YES
minValue Number R&W getMinimumValue, setMinimumValue YES
maxValue Number R&W getMaximumValue, setMaximumValue YES
minAllowedValue Number R&W getMinimumAllowedValue, setMinimumAllowedValue YES
maxAllowedValue Number R&W getMaximumAllowedValue, setMaximumAllowedValue YES
thumbSprite Number readonly getThumbSprite YES
progressSprite cc.Sprite readonly getProgressSprite YES
backgroundSprite cc.Sprite readonly getBackgroundSprite YES

cc.ControlStepper

Extend from cc.Control

Property Type Accessibility Getter/Setter function Advanced Compress Ready
wraps Boolean R&W getWraps, setWraps YES
value Number R&W getValue, setValue YES
minValue Number R&W getMinimumValue, setMinimumValue YES
maxValue Number R&W getMaximumValue, setMaximumValue YES
stepValue Number R&W getStepValue, setStepValue YES
continuous Boolean readonly isContinuous YES
minusSprite cc.Sprite R&W getMinusSprite, setMinusSprite YES
plusSprite cc.Sprite R&W getPlusSprite, setPlusSprite YES
minusLabel cc.LabelTTF R&W getMinusLabel, setMinusLabel YES
plusSLabel cc.LabelTTF R&W None NO

cc.Scale9Sprite

Extend from cc.NodeRGBA

Property Type Accessibility Getter/Setter function Advanced Compress Ready
preferredSize cc.Size R&W getPreferredSize, setPreferredSize YES
capInsets cc.Rect R&W getCapInsets, setCapInsets YES
insetLeft Number R&W getInsetLeft, setInsetLeft YES
insetTop Number R&W getInsetTop, setInsetTop YES
insetRight Number R&W getInsetRight, setInsetRight YES
insetBottom Number R&W getInsetBottom, setInsetBottom YES

cc.TableViewCell

Extend from cc.Node

Property Type Accessibility Getter/Setter function Advanced Compress Ready
objectId Number R&W getObjectID, setObjectID YES

转载请注明:http://www.cocos2dx.net/post/235

时间: 2024-10-22 13:02:28

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

【cocos2d-js官方文档】二十一、v3相对于v2版本的api变动

CCAudio.js SimpleAudioEngine.js改名为CCAudio.js. AudioEngine中删除了以下几个方法: preloadMusic preloadEffect isFormatSupported preloadSound cc.AudioEngine.end被移到了实例中,而不是作为类的静态方法. cc.textureCache 删除了以下的几个api: cc.loadImg cc.loadImage.handler cc.computeImageFormatTy

【cocos2d-js官方文档】五、Cocos2d-JS v3.0的新Action API

新增action中的方法 曾经,当我们须要反复一个action的时候,我们须要: sprite.runAction(cc.Repeat.create(action, 2)); 上面代码中创建了一个新的Repeat对象又一次包装action,这样无论在语义上还是代码上都比較难理解. 为什么我们不能像jQuery一样的简单方便的使用原action呢? 于是我们在新版本号中为action添加了新的方法: sprite.runAction(action.repeat(2)); 要循环action仅仅须要

ArcGIS API For JS官方文档解析教程

ArcGIS API For JavaScript(八)之Arcade ArcGIS API For JavaScript官方文档(一)之关于API ArcGIS API For JavaScript官方文档(一)之默认API配置 ArcGIS API For JavaScript官方文档(七)之编辑 ArcGIS API For Javascript官方文档(三)之从Web服务器取回数据 ArcGIS API For JavaScript官方文档(二)之默认的API字符串 ArcGIS API

【cocos2d-js官方文档】二十五、Cocos2d-JS v3.0中的单例对象

为何将单例模式移除 在Cocos2d-JS v3.0之前.全部API差点儿都是从Cocos2d-x中移植过来的,这是Cocos2d生态圈统一性的重要一环.可惜的是,这样的统一性也在非常大程度上限制了Cocos2d-html5的发展,有一些在C++中非常有意义的涉及搬到Html5平台后却使得Cocos2d-html5变得臃肿.所以在3.0版中,我们决定将一些API改造成更适合JavaScript开发者的API.这篇文档中将要展示的是单例类的改造. 拿cc.SpriteFrameCache为例: /

【cocos2d-js官方文档】十八、Cocos2d-js v3.0的对象构造和类继承

在Cocos2d-JS中,对象的构造方式和Cocos2d-x一样,使用各个类的create函数来构造.在Cocos2d-JS v3.0我们还将为你带来一种传统的方式,即使用new操作符.另外,在v3.0 alpha1版本中,因为我们还没有找到较好的解决办法,所以不能继承JSB中的引擎类.但是在v3.0 alpha2中,这个问题已经解决了.由于使用new操作符,编写继承代码也更加容易了. 在这篇文档中,我们将会介绍如何使用它们,以及简要的实现原理. 1. 弃用的create函数 由于Cocos2d

Hui 2.x.js 官方文档

基础方法 // 判断值是否是指定数据类型 var result = hui.isTargetType("白签软件", "string"); //=>true var result = hui.isTargetType(123, "number"); // =>true var result = hui.isTargetType("false", "boolean"); // =>false

【cocos2d-js官方文档】八、cc.game

概述 使用cc.game单例代替了原有的cc.Application以及cc.AppControl. 简化了工程启动代码的编写. 使用 首先在index.html中引入xxx/frameworks/cocos2d-html5/CCBoot.js. 然后开始进行入口代码编写,一般放在main.js中. 项目启动代码的编写较v2版本是大大的精简了,使用起来会更加舒服: cc.game.onStart = function(){ //load resources cc.LoaderScene.prel

node.js官方文档chm电子书的制作

制作软件:WebCHMSetup2.22.zip,http://www.onlinedown.net/soft/31553.htm 制作好的电子书:Node.js(v6.10.2).zip 参考链接:https://www.zhihu.com/question/37005587

bootbox.js官方文档

简介 Bootbox.js是一个小型的JavaScript库,基于Bootstrap模态框开发,用于创建可编程的对话框. 不像原生的alert等对话框,所有的Bootstrap模态框生成的都是非阻塞事件.所以 在使用confirm()对话框时,请记住这一点,因为它不是本地确认对话框的替代. 任何取决于用户选择的代码都必须放在回调函数中. alert alert是只有单个按钮的对话框,按ESC键或单击关闭按钮可关闭对话框. bootbox.alert("Your message here…&quo