raw version for blend function in sprite

This commit is contained in:
Huabing.Xu
2016-02-15 14:24:38 +08:00
parent 58c3bbd0fe
commit 39f1d6d5ce
2 changed files with 54 additions and 7 deletions
+32
View File
@@ -72,6 +72,10 @@ var Sprite = cc.Class({
inspector: 'app://editor/page/inspector/sprite.html'
},
ctor: function() {
this._blendFunc = cc.BlendFunc.ALPHA_NON_PREMULTIPLIED;
},
properties: {
_spriteFrame: {
default: null,
@@ -202,6 +206,33 @@ var Sprite = cc.Class({
animatable: false
},
/**
* specify the blend function
* */
srcBlendFactor: {
get: function() {
return this._blendFunc.src;
},
set: function(value) {
this._blendFunc.src = value;
this._sgNode.setBlendFunc(this._blendFunc);
},
animatable: false,
type:cc.BlendFunc.BlendFactor
},
dstBlendFactor: {
get: function() {
return this._blendFunc.dst;
},
set: function(value) {
this._blendFunc.dst = value;
this._sgNode.setBlendFunc(this._blendFunc);
},
animatable: false,
type:cc.BlendFunc.BlendFactor
},
//FIXME:_useOriginalSize is deprecated, since v0.8, it need to be deleted
useOriginalSize: {
get: function () {
@@ -529,6 +560,7 @@ var Sprite = cc.Class({
sgNode.setFillStart(this._fillStart);
sgNode.setFillRange(this._fillRange);
sgNode.enableTrimmedContentSize(this._isTrimmedMode);
sgNode.setBlendFunc(this._blendFunc);
},
_resized: function () {
+22 -7
View File
@@ -60,19 +60,36 @@ cc.BlendFunc = function (src1, dst1) {
this.dst = dst1;
};
var BlendFactor = cc.Enum({
ONE: 1, //cc.ONE
ZERO: 0, //cc.ZERO
SRC_ALPHA: 0x0302, //cc.SRC_ALPHA
SRC_COLOR: 0x300, //cc.SRC_COLOR
DST_ALPHA: 0x304, //cc.DST_ALPHA
DST_COLOR: 0x306, //cc.DST_COLOR
ONE_MINUS_SRC_ALPHA: 0x303, //cc.ONE_MINUS_SRC_ALPHA
ONE_MINUS_SRC_COLOR: 0x301, //cc.ONE_MINUS_SRC_COLOR
ONE_MINUS_DST_ALPHA: 0x305, //cc.ONE_MINUS_DST_ALPHA
ONE_MINUS_DST_COLOR: 0x307, //cc.ONE_MINUS_DST_COLOR
});
//var BlendFactor = cc;
cc.BlendFunc._disable = function(){
return new cc.BlendFunc(cc.ONE, cc.ZERO);
return new cc.BlendFunc(BlendFactor.ONE, BlendFactor.ZERO);
};
cc.BlendFunc._alphaPremultiplied = function(){
return new cc.BlendFunc(cc.ONE, cc.ONE_MINUS_SRC_ALPHA);
return new cc.BlendFunc(BlendFactor.ONE, BlendFactor.ONE_MINUS_SRC_ALPHA);
};
cc.BlendFunc._alphaNonPremultiplied = function(){
return new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA);
return new cc.BlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ONE_MINUS_SRC_ALPHA);
};
cc.BlendFunc._additive = function(){
return new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE);
return new cc.BlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ONE);
};
cc.BlendFunc.BlendFactor = BlendFactor;
/** @expose */
cc.BlendFunc.DISABLE;
cc.js.get(cc.BlendFunc, "DISABLE", cc.BlendFunc._disable);
@@ -90,9 +107,7 @@ cc.js.get(cc.BlendFunc, "ADDITIVE", cc.BlendFunc._additive);
* @method blendFuncDisable
* @returns {BlendFunc}
*/
cc.blendFuncDisable = function () {
return new cc.BlendFunc(cc.ONE, cc.ZERO);
};
cc.blendFuncDisable = cc.BlendFunc._disable;
/**
* Common usage: