isRunning function for Sprite object

This commit is contained in:
Лаврёнов Антон 2014-03-02 10:46:45 +08:00
parent 86178185bc
commit 53ac9329de
2 changed files with 51 additions and 0 deletions

View File

@ -136,6 +136,15 @@
this.anim.stop();
clearInterval(this.interval);
},
/**
* determine if animation of sprite is running or not. returns true or false
* @method
* @memberof Kinetic.Animation.prototype
* @returns {Boolean}
*/
isRunning: function() {
return this.anim.isRunning();
},
_updateIndex: function() {
var index = this.frameIndex(),
animation = this.getAnimation(),

View File

@ -72,6 +72,48 @@ suite('Sprite', function() {
};
imageObj.src = 'assets/scorpion-sprite.png';
});
test('check is sprite running', function(done){
var imageObj = new Image();
imageObj.onload = function() {
var stage = addStage();
var layer = new Kinetic.Layer();
var sprite = new Kinetic.Sprite({
x: 200,
y: 50,
image: imageObj,
animation: 'standing',
animations: {
standing: [
0, 0, 49, 109,
52, 0, 49, 109,
105, 0, 49, 109,
158, 0, 49, 109,
210, 0, 49, 109,
262, 0, 49, 109
]
},
frameRate: 50,
draggable: true,
shadowColor: 'black',
shadowBlur: 3,
shadowOffset: {x: 3, y:1},
shadowOpacity: 0.3
});
layer.add(sprite);
stage.add(layer);
assert.equal(sprite.isRunning(), false);
sprite.start();
assert.equal(sprite.isRunning(), true);
sprite.stop();
done();
};
imageObj.src = 'assets/scorpion-sprite.png';
});
test.skip('can change frame rate on fly', function(done){
var imageObj = new Image();
imageObj.onload = function() {