Merge pull request #478 from 2youyouo2/anim

add playAdditive
This commit is contained in:
Wang Nan
2016-03-16 09:21:22 +08:00
2 changed files with 89 additions and 1 deletions
+24 -1
View File
@@ -174,13 +174,36 @@ var Animation = cc.Class({
},
/**
* Plays an animation.
* Plays an animation and stop other animations.
* @method play
* @param {String} [name] - The name of animation to play. If no name is supplied then the default animation will be played.
* @param {Number} [startTime] - play an animation from startTime
* @return {AnimationState} - The AnimationState of playing animation. In cases where the animation can't be played (ie, there is no default animation or no animation with the specified name), the function will return null.
*/
play: function (name, startTime) {
var state = this.playAdditive(name, startTime);
var playingStates = this._animator.playingAnims;
for (var i = playingStates.length; i >= 0; i--) {
if (playingStates[i] === state) {
continue;
}
this._animator.stopState(playingStates[i]);
}
return state;
},
/**
* Plays an additive animation, it will not stop other animations.
* If there are other animations playing, then will play several animations at the same time.
* @method playAdditive
* @param {String} [name] - The name of animation to play. If no name is supplied then the default animation will be played.
* @param {Number} [startTime] - play an animation from startTime
* @return {AnimationState} - The AnimationState of playing animation. In cases where the animation can't be played (ie, there is no default animation or no animation with the specified name), the function will return null.
*/
playAdditive: function (name, startTime) {
this._init();
var state = this.getAnimationState(name || this._defaultClip.name);
if (state) {
+65
View File
@@ -1138,3 +1138,68 @@ test('stop Animation', function () {
strictEqual(animation._animator.playingAnims.length, 0, 'playing anims should be 0');
});
test('play Animation', function () {
var entity = new cc.Node();
var animation = entity.addComponent(cc.Animation);
var clip = new cc.AnimationClip();
clip._name = 'move';
clip._duration = 1;
clip.curveData = {
props: {
x: [
{frame: 0, value: 0},
{frame: 1, value: 100}
]
}
};
animation.addClip(clip);
clip = new cc.AnimationClip();
clip._name = 'rotate';
clip._duration = 1;
clip.curveData = {
props: {
rotation: [
{frame: 0, value: 0},
{frame: 1, value: 90}
]
}
};
animation.addClip(clip);
clip = new cc.AnimationClip();
clip._name = 'scale';
clip._duration = 1;
clip.curveData = {
props: {
scaleX: [
{frame: 0, value: 1},
{frame: 1, value: 2}
]
}
};
animation.addClip(clip);
var moveState = animation.getAnimationState('move');
var rotateState = animation.getAnimationState('rotate');
strictEqual(moveState.isPlaying, false, 'move animation state should not be playing');
strictEqual(rotateState.isPlaying, false, 'rotate animation state should not be playing');
animation.play('move');
strictEqual(moveState.isPlaying, true, 'move animation state should be playing');
strictEqual(rotateState.isPlaying, false, 'rotate animation state should not be playing');
animation.play('rotate');
strictEqual(moveState.isPlaying, false, 'move animation state should not be playing');
strictEqual(rotateState.isPlaying, true, 'rotate animation state should be playing');
animation.playAdditive('move');
strictEqual(moveState.isPlaying, true, 'move animation state should be playing');
strictEqual(rotateState.isPlaying, true, 'rotate animation state should be playing');
animation.play('scale');
strictEqual(moveState.isPlaying, false, 'move animation state should not be playing');
strictEqual(rotateState.isPlaying, false, 'rotate animation state should be playing');
});