Material
Class
Extends Asset
Material Asset.
Index
Properties
url
String
cc.Asset.url
is deprecated, please use nativeUrl instead_uuid
String
loaded
Boolean
Whether the asset is loaded or not.nativeUrl
String
Returns the url of this asset's native object, if none it will returns an empty string.refCount
Number
The number of reference_native
String
Serializable url for native asset._nativeAsset
Object
The underlying native asset of this asset if one is available._name
String
_objFlags
Number
name
String
The name of the object.isValid
Boolean
Indicates whether the object is not yet destroyed.
Methods
getBuiltinMaterial
Get built-in materialscreateWithBuiltin
Creates a Material with builtin Effect.create
Creates a Material.setProperty
Sets the Material propertygetProperty
Gets the Material property.define
Sets the Material define.getDefine
Gets the Material define.setCullMode
Sets the Material cull mode.setDepth
Sets the Material depth states.setBlend
Sets the Material blend states.setStencilEnabled
Sets whether enable the stencil test.setStencil
Sets the Material stencil render states.toString
Returns the asset's url.serialize
Provide this method at the request of AssetDB.createNode
Create a new node using this asset in the scene...._setRawAsset
Set native file name for this asset.addRef
Add references of assetdecRef
Reduce references of asset and it will be auto released when refCount equals 0.destroy
Actual object destruction will delayed until before rendering._destruct
Clear all references in the instance._onPreDestroy
Called before the object being destroyed._serialize
The customized serialization for this object._deserialize
Init this object from the custom serialized data.
Details
Properties
url
cc.Asset.url
is deprecated, please use nativeUrl instead
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/asset-manager/deprecated.js:728 |
Deprecated | cc.Asset.url is deprecated, please use cc.Asset.nativeUrl instead |
_uuid
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/assets/CCAsset.js:57 |
loaded
Whether the asset is loaded or not.
meta | description |
---|---|
Type | Boolean |
Defined in | cocos2d/core/assets/CCAsset.js:66 |
nativeUrl
Returns the url of this asset's native object, if none it will returns an empty string.
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/assets/CCAsset.js:81 |
refCount
The number of reference
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/assets/CCAsset.js:115 |
_native
Serializable url for native asset.
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/assets/CCAsset.js:131 |
_nativeAsset
The underlying native asset of this asset if one is available. This property can be used to access additional details or functionality releated to the asset. This property will be initialized by the loader if
_native
is available.
meta | description |
---|---|
Type | Object |
Defined in | cocos2d/core/assets/CCAsset.js:142 |
_name
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/platform/CCObject.js:76 |
_objFlags
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/platform/CCObject.js:83 |
name
The name of the object.
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/platform/CCObject.js:240 |
Examples
obj.name = "New Obj";
isValid
Indicates whether the object is not yet destroyed. (It will not be available after being destroyed)
When an object'sdestroy
is called, it is actually destroyed after the end of this frame. SoisValid
will return false from the next frame, whileisValid
in the current frame will still be true. If you want to determine whether the current frame has calleddestroy
, usecc.isValid(obj, true)
, but this is often caused by a particular logical requirements, which is not normally required.
meta | description |
---|---|
Type | Boolean |
Defined in | cocos2d/core/platform/CCObject.js:258 |
Examples
var node = new cc.Node();
cc.log(node.isValid); // true
node.destroy();
cc.log(node.isValid); // true, still valid in this frame
// after a frame...
cc.log(node.isValid); // false, destroyed in the end of last frame
Methods
getBuiltinMaterial
Get built-in materials
meta | description |
---|---|
Returns | Material |
Defined in | cocos2d/core/assets/material/CCMaterial.js:151 |
Parameters
name
string
createWithBuiltin
Creates a Material with builtin Effect.
meta | description |
---|---|
Returns | Material |
Defined in | cocos2d/core/assets/material/CCMaterial.js:168 |
Parameters
create
Creates a Material.
meta | description |
---|---|
Returns | Material |
Defined in | cocos2d/core/assets/material/CCMaterial.js:181 |
Parameters
effectAsset
EffectAssettechniqueIndex
number
setProperty
Sets the Material property
meta | description |
---|---|
Defined in | cocos2d/core/assets/material/CCMaterial.js:199 |
Parameters
getProperty
Gets the Material property.
meta | description |
---|---|
Returns | Object |
Defined in | cocos2d/core/assets/material/CCMaterial.js:230 |
Parameters
define
Sets the Material define.
meta | description |
---|---|
Defined in | cocos2d/core/assets/material/CCMaterial.js:245 |
Parameters
getDefine
Gets the Material define.
meta | description |
---|---|
Returns | boolean | number |
Defined in | cocos2d/core/assets/material/CCMaterial.js:263 |
Parameters
setCullMode
Sets the Material cull mode.
meta | description |
---|---|
Defined in | cocos2d/core/assets/material/CCMaterial.js:278 |
Parameters
setDepth
Sets the Material depth states.
meta | description |
---|---|
Defined in | cocos2d/core/assets/material/CCMaterial.js:289 |
Parameters
setBlend
Sets the Material blend states.
meta | description |
---|---|
Defined in | cocos2d/core/assets/material/CCMaterial.js:307 |
Parameters
enabled
booleanblendEq
numberblendSrc
numberblendDst
numberblendAlphaEq
numberblendSrcAlpha
numberblendDstAlpha
numberblendColor
numberpassIdx
number
setStencilEnabled
Sets whether enable the stencil test.
meta | description |
---|---|
Defined in | cocos2d/core/assets/material/CCMaterial.js:335 |
Parameters
setStencil
Sets the Material stencil render states.
meta | description |
---|---|
Defined in | cocos2d/core/assets/material/CCMaterial.js:346 |
Parameters
stencilTest
numberstencilFunc
numberstencilRef
numberstencilMask
numberstencilFailOp
numberstencilZFailOp
numberstencilZPassOp
numberstencilWriteMask
numberpassIdx
number
toString
Returns the asset's url.
The Asset
object overrides the toString()
method of the Object
object.
For Asset
objects, the toString()
method returns a string representation of the object.
JavaScript calls the toString()
method automatically when an asset is to be represented as a text value or when a texture is referred to in a string concatenation.
meta | description |
---|---|
Returns | String |
Defined in | cocos2d/core/assets/CCAsset.js:212 |
serialize
Provide this method at the request of AssetDB.
meta | description |
---|---|
Returns | String |
Defined in | cocos2d/core/assets/CCAsset.js:232 |
createNode
Create a new node using this asset in the scene.
If this type of asset dont have its corresponding node type, this method should be null.
meta | description |
---|---|
Defined in | cocos2d/core/assets/CCAsset.js:246 |
Parameters
_setRawAsset
Set native file name for this asset.
meta | description |
---|---|
Defined in | cocos2d/core/assets/CCAsset.js:261 |
Parameters
addRef
Add references of asset
meta | description |
---|---|
Returns | Asset |
Defined in | cocos2d/core/assets/CCAsset.js:283 |
decRef
Reduce references of asset and it will be auto released when refCount equals 0.
meta | description |
---|---|
Returns | Asset |
Defined in | cocos2d/core/assets/CCAsset.js:301 |
destroy
Destroy this Object, and release all its own references to other objects.
Actual object destruction will delayed until before rendering.
From the next frame, this object is not usable anymore.
You can use cc.isValid(obj)
to check whether the object is destroyed before accessing it.
meta | description |
---|---|
Returns | Boolean |
Defined in | cocos2d/core/platform/CCObject.js:293 |
Examples
obj.destroy();
_destruct
Clear all references in the instance.
NOTE: this method will not clear the getter
or setter
functions which defined in the instance of CCObject
.
You can override the _destruct
method if you need, for example:
_destruct: function () {
for (var key in this) {
if (this.hasOwnProperty(key)) {
switch (typeof this[key]) {
case 'string':
this[key] = '';
break;
case 'object':
case 'function':
this[key] = null;
break;
}
}
}
meta | description |
---|---|
Defined in | cocos2d/core/platform/CCObject.js:427 |
_onPreDestroy
Called before the object being destroyed.
meta | description |
---|---|
Defined in | cocos2d/core/platform/CCObject.js:483 |
_serialize
The customized serialization for this object. (Editor Only)
meta | description |
---|---|
Returns | object |
Defined in | cocos2d/core/platform/CCObject.js:511 |
Parameters
exporting
Boolean
_deserialize
Init this object from the custom serialized data.
meta | description |
---|---|
Defined in | cocos2d/core/platform/CCObject.js:524 |
Parameters
data
Object the serialized json datactx
_Deserializer