From 90a5891f98018b648b186f91fcf8224d25575bd1 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Wed, 4 May 2016 16:23:37 +0800 Subject: [PATCH] add constant curve type --- cocos2d/animation/easing.js | 1 + cocos2d/animation/motion-path-helper.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cocos2d/animation/easing.js b/cocos2d/animation/easing.js index af51505fa4..5bd051dc68 100644 --- a/cocos2d/animation/easing.js +++ b/cocos2d/animation/easing.js @@ -1,4 +1,5 @@ var Easing = { + constant: function () { return 0; }, linear: function (k) { return k; }, // quad diff --git a/cocos2d/animation/motion-path-helper.js b/cocos2d/animation/motion-path-helper.js index f78535e1a6..8b43ab7cbd 100644 --- a/cocos2d/animation/motion-path-helper.js +++ b/cocos2d/animation/motion-path-helper.js @@ -246,6 +246,7 @@ function sampleMotionPaths (motionPaths, data, duration, fps) { var startRatioOffset = 0; var EPSILON = 1e-6; + var newType = DynamicAnimCurve.Linear; // do not need to compute last path for (var i = 0, l = motionPaths.length; i < l-1; i++) { @@ -329,9 +330,11 @@ function sampleMotionPaths (motionPaths, data, duration, fps) { } } + newType = type === 'constant' ? type : DynamicAnimCurve.Linear; + for (var j = 0, l2 = results.length; j < l2; j++) { var newRatio = ratio + startRatioOffset + speed * j * betweenRatio; - addNewDatas(results[j], DynamicAnimCurve.Linear, newRatio); + addNewDatas(results[j], newType, newRatio); } if (Math.abs(progress - 1) > EPSILON) // progress > 1 @@ -341,7 +344,7 @@ function sampleMotionPaths (motionPaths, data, duration, fps) { } if (ratios[ratios.length - 1] !== newRatios[newRatios.length -1]) { - addNewDatas(values[values.length - 1], DynamicAnimCurve.Linear, ratios[ratios.length - 1]); + addNewDatas(values[values.length - 1], newType, ratios[ratios.length - 1]); } }