Merge branches 'v1.3' and 'v1.3' of github.com:cocos-creator/engine into v1.3

This commit is contained in:
Jare Guo
2016-10-10 15:42:49 +08:00
6 changed files with 106 additions and 7 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ p.playState = function (state, startTime) {
state.play();
if (typeof startTime === 'number') {
state.time = startTime;
state.setTime(startTime);
}
this.play();
+30 -3
View File
@@ -297,7 +297,15 @@ var EventAnimCurve = cc.Class({
* @type {Object}
* @default null
*/
_lastWrappedInfo: null
_lastWrappedInfo: null,
/**
* Ignore event index
* @property _ignoreIndex
* @type {number}
* @default NaN
*/
_ignoreIndex: NaN
},
_wrapIterations: function (iterations) {
@@ -318,6 +326,10 @@ var EventAnimCurve = cc.Class({
if (direction < 0) currentIndex += 1;
}
if (this._ignoreIndex !== currentIndex) {
this._ignoreIndex = NaN;
}
var lastWrappedInfo = this._lastWrappedInfo;
currentWrappedInfo.frameIndex = currentIndex;
@@ -377,7 +389,7 @@ var EventAnimCurve = cc.Class({
},
_fireEvent: function (index) {
if (index < 0 || index >= this.events.length) return;
if (index < 0 || index >= this.events.length || this._ignoreIndex === index) return;
var eventInfo = this.events[index];
var events = eventInfo.events;
@@ -396,8 +408,23 @@ var EventAnimCurve = cc.Class({
}
},
onTimeChangedManually: function () {
onTimeChangedManually: function (time, animationNode) {
this._lastWrappedInfo = null;
this._ignoreIndex = NaN;
var info = animationNode.getWrappedInfo(time);
var direction = info.direction;
var frameIndex = binarySearch(this.ratios, info.ratio);
// only ignore when time not on a frame index
if (frameIndex < 0) {
frameIndex = ~frameIndex - 1;
// if direction is inverse, then increase index
if (direction < 0) frameIndex += 1;
this._ignoreIndex = frameIndex;
}
}
});
+2 -1
View File
@@ -88,8 +88,9 @@ state.onStop = function () {
state.setTime = function (time) {
this.time = time || 0;
var self = this;
this.curves.forEach(function (curve) {
curve.onTimeChangedManually();
curve.onTimeChangedManually(time, self);
});
};
+19 -1
View File
@@ -111,10 +111,23 @@ var PageView = cc.Class({
default: 0.5,
type: cc.Float,
slide: true,
range: [0, 1, 0.1],
range: [0, 1, 0.01],
tooltip: 'i18n:COMPONENT.pageview.scrollThreshold'
},
/**
* !#en Change the AutoScroll stop epsilon value of PageView, change this value could adjust the PageView's
* event triggerring timing.
* !#zh 设置 PageView 页面自动滚动动画结束的阈值,修改此值可以调整 PageView 事件的发送时机。
* @property {Number} autoScrollStopEpsilon
*/
autoScrollStopEpsilon: {
default: 0.1,
type: cc.Float,
range: [0, 1, 0.01],
tooltip: 'i18n:COMPONENT.pageview.autoScrollStopEpsilon'
},
/**
* !#en The Page View Indicator
* !#zh 页面视图指示器组件
@@ -300,6 +313,11 @@ var PageView = cc.Class({
}
},
//override the method of ScrollView
getAutoScrollStopEpsilon: function () {
return this.autoScrollStopEpsilon;
},
// 刷新页面视图
_updatePageView: function () {
var pageCount = this._pages.length;
+9 -1
View File
@@ -1088,6 +1088,10 @@ var ScrollView = cc.Class({
return false;
},
getAutoScrollStopEpsilon: function () {
return EPSILON;
},
_processAutoScrolling: function(dt) {
var isAutoScrollBrake = this._isNecessaryAutoScrollBrake();
@@ -1100,7 +1104,11 @@ var ScrollView = cc.Class({
}
var newPosition = cc.pAdd(this._autoScrollStartPosition, cc.pMult(this._autoScrollTargetDelta, percentage));
var reachedEnd = (percentage === 1);
var reachedEnd = Math.abs(percentage - 1) <= this.getAutoScrollStopEpsilon();
if(reachedEnd) {
newPosition = cc.pAdd(this._autoScrollStartPosition, this._autoScrollTargetDelta);
}
if (this.elastic) {
var brakeOffsetPosition = cc.pSub(newPosition, this._autoScrollBrakingStartPosition);
+45
View File
@@ -882,6 +882,51 @@ test('EventAnimCurve', function () {
], 'should triggered frame 5 event once if speed is -1');
state.speed = 1;
state.wrapMode = cc.WrapMode.Normal;
animation.stop('test');
animation.play('test', 1.1);
calls = [];
manager.update(0);
manager.update(1);
deepEqual(calls, [
{
func: 'func1',
args: ['Frame 3 Event triggered']
},
{
func: 'func1',
args: ['Frame 4 Event triggered']
},
{
func: 'func1',
args: ['Frame 5 Event triggered']
}
], 'should triggered from frame 3 to frame 5');
state.wrapMode = cc.WrapMode.Reverse;
animation.stop('test');
animation.play('test', 1.1);
calls = [];
manager.update(0);
manager.update(1);
deepEqual(calls, [
{
func: 'func2',
args: [1,2]
},
{
func: 'func3',
args: ['Second event on frame 0.4']
},
{
func: 'func1',
args: ['Frame 0 Event triggered']
}
], 'should triggered from frame 2 to frame 0');
// new clip
clip = new cc.AnimationClip();
clip._duration = 2;