Skip to content

Commit

Permalink
Merge branch 'v1.3' of github.com:cocos-creator/engine into v1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nantas committed Dec 20, 2016
2 parents fa8cae5 + fb65f2f commit 1719ccf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cocos2d/clipping-nodes/CCClippingNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @property {_ccsg.Node} stencil - he ccsg.Node to use as a stencil to do the clipping.
*/
cc.ClippingNode = _ccsg.Node.extend(/** @lends cc.ClippingNode# */{
alphaThreshold: 0,
alphaThreshold: 1,
inverted: false,

_stencil: null,
Expand Down
3 changes: 3 additions & 0 deletions cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ proto.setStencil = function(stencil){
}
};

// should reset program used by _stencil
proto.resetProgramByStencil = function () { };

proto._restoreCmdCallback = function (ctx) {
var wrapper = ctx || cc._renderContext;
wrapper.restore();
Expand Down
20 changes: 14 additions & 6 deletions cocos2d/core/components/CCMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ var Mask = cc.Class({

/**
* !#en
* The alpha threshold. <br/>
* The alpha threshold.(Not supported Canvas Mode) <br/>
* The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold. <br/>
* Should be a float between 0 and 1. <br/>
* This default to 1 (so alpha test is disabled).
* !#zh
* Alpha 阈值 <br/>
* Alpha 阈值(不支持 Canvas 模式)<br/>
* 只有当模板的像素的 alpha 大于 alphaThreshold 时,才会绘制内容。<br/>
* 该数值 0 ~ 1 之间的浮点数,默认值为 1(因此禁用 alpha)
* @property alphaThreshold
Expand All @@ -133,13 +133,17 @@ var Mask = cc.Class({
slide: true,
tooltip: 'i18n:COMPONENT.mask.alphaThreshold',
notify: function() {
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
cc.warn("The alphaThreshold invalid in Canvas Mode.");
return;
}
this._sgNode.setAlphaThreshold(this.alphaThreshold);
}
},

/**
* !#en Reverse mask
* !#zh 反向遮罩
* !#en Reverse mask (Not supported Canvas Mode)
* !#zh 反向遮罩(不支持 Canvas 模式)
* @property inverted
* @type {Boolean}
* @default false
Expand All @@ -149,6 +153,10 @@ var Mask = cc.Class({
type: cc.Boolean,
tooltip: 'i18n:COMPONENT.mask.inverted',
notify: function() {
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
cc.warn("The inverted invalid in Canvas Mode.");
return;
}
this._sgNode.setInverted(this.inverted);
}
},
Expand Down Expand Up @@ -251,7 +259,7 @@ var Mask = cc.Class({
this.node.off('size-changed', this._refreshStencil, this);
this.node.off('anchor-changed', this._refreshStencil, this);
},

_calculateCircle: function(center, radius, segements) {
var polies =[];
var anglePerStep = Math.PI * 2 / segements;
Expand All @@ -276,6 +284,7 @@ var Mask = cc.Class({
}
stencil.setContentSize(contentSize);
stencil.setAnchorPoint(anchorPoint);
this._sgNode.setAlphaThreshold(this.alphaThreshold);
}
else {
var isDrawNode = stencil instanceof cc.DrawNode;
Expand Down Expand Up @@ -309,7 +318,6 @@ var Mask = cc.Class({
}
}
this._sgNode.setInverted(this.inverted);
this._sgNode.setAlphaThreshold(this.alphaThreshold);
this._clippingStencil = stencil;
if (!CC_JSB) {
cc.renderer.childrenOrderDirty = true;
Expand Down
11 changes: 8 additions & 3 deletions cocos2d/core/components/CCPageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,20 +530,25 @@ var PageView = cc.Class({

_getDragDirection: function (moveOffset) {
if (this.direction === Direction.Horizontal) {
if (moveOffset.x === 0) { return 0; }
return (moveOffset.x > 0 ? 1 : -1);
}
else if (this.direction === Direction.Vertical) {
// 由于滚动 Y 轴的原点在在右上角所以应该是小于 0
if (moveOffset.y === 0) { return 0; }
return (moveOffset.y < 0 ? 1 : -1);
}
},

_handleReleaseLogic: function(touch) {
var bounceBackStarted = this._startBounceBackIfNeeded();
var index = this._curPageIdx, nextIndex = 0;
var moveOffset = cc.pSub(this._touchBeganPosition, this._touchEndPosition);
if (bounceBackStarted) {
if (this._getDragDirection(moveOffset) > 0) {
var dragDirection = this._getDragDirection(moveOffset);
if (dragDirection === 0) {
return;
}
if (dragDirection > 0) {
this._curPageIdx = this._pages.length - 1;
}
else {
Expand All @@ -554,7 +559,7 @@ var PageView = cc.Class({
}
}
else {
nextIndex = index + this._getDragDirection(moveOffset);
var index = this._curPageIdx, nextIndex = index + this._getDragDirection(moveOffset);
if (nextIndex < this._pages.length) {
if (this._isScrollable(moveOffset, index, nextIndex)) {
this.scrollToPage(nextIndex);
Expand Down
12 changes: 11 additions & 1 deletion cocos2d/core/load-pipeline/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ function downloadScript (item, callback, isAsync) {
d.body.appendChild(s);
}

function downloadWebp (item, callback, isCrossOrigin, img) {
if (!cc.sys.capabilities.webp) {
setTimeout(function () {
callback('Load Webp ( ' + item.url + ' ) failed')
}, 0);
return;
}
downloadImage(item, callback, isCrossOrigin, img);
}

function downloadImage (item, callback, isCrossOrigin, img) {
if (isCrossOrigin === undefined) {
isCrossOrigin = true;
Expand Down Expand Up @@ -232,7 +242,7 @@ var defaultMap = {
'gif' : downloadImage,
'ico' : downloadImage,
'tiff' : downloadImage,
'webp' : downloadImage,
'webp' : downloadWebp,
'image' : downloadImage,

// Audio
Expand Down
4 changes: 3 additions & 1 deletion cocos2d/core/platform/CCSys.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ else {
};
}

var _supportWebp = _tmpCanvas1.toDataURL('image/webp').startsWith('data:image/webp');
var _supportCanvas = !!_tmpCanvas1.getContext("2d");
var _supportWebGL = false;
if (win.WebGLRenderingContext) {
Expand Down Expand Up @@ -792,7 +793,8 @@ else {
*/
var capabilities = sys.capabilities = {
"canvas": _supportCanvas,
"opengl": _supportWebGL
"opengl": _supportWebGL,
"webp": _supportWebp,
};
if (docEle['ontouchstart'] !== undefined || doc['ontouchstart'] !== undefined || nav.msPointerEnabled)
capabilities["touches"] = true;
Expand Down

0 comments on commit 1719ccf

Please sign in to comment.