mirror of
https://github.com/konvajs/konva.git
synced 2025-04-24 19:03:56 +08:00
fix #447
This commit is contained in:
parent
7e62414f0c
commit
08d9be8371
@ -60,6 +60,17 @@
|
|||||||
// reset index when animation changes
|
// reset index when animation changes
|
||||||
this.frameIndex(0);
|
this.frameIndex(0);
|
||||||
});
|
});
|
||||||
|
// smooth change for frameRate
|
||||||
|
var that = this;
|
||||||
|
this.on('frameRateChange.kinetic', function() {
|
||||||
|
if (!this.anim.isRunning()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearInterval(this.interval);
|
||||||
|
this.interval = setInterval(function() {
|
||||||
|
that._updateIndex();
|
||||||
|
}, 1000 / this.getFrameRate());
|
||||||
|
});
|
||||||
|
|
||||||
this.sceneFunc(this._sceneFunc);
|
this.sceneFunc(this._sceneFunc);
|
||||||
this.hitFunc(this._hitFunc);
|
this.hitFunc(this._hitFunc);
|
||||||
|
@ -72,4 +72,60 @@ suite('Sprite', function() {
|
|||||||
};
|
};
|
||||||
imageObj.src = 'assets/scorpion-sprite.png';
|
imageObj.src = 'assets/scorpion-sprite.png';
|
||||||
});
|
});
|
||||||
|
test("can change frame rate on fly", 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.frameRate(), 50);
|
||||||
|
setTimeout(function(){
|
||||||
|
sprite.frameRate(100);
|
||||||
|
assert.equal(sprite.frameRate(), 100);
|
||||||
|
// don't run animation after change frame rate
|
||||||
|
assert.equal(sprite.anim.isRunning(), false);
|
||||||
|
|
||||||
|
sprite.start();
|
||||||
|
}, 23);
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
sprite.frameRate(52);
|
||||||
|
assert.equal(sprite.anim.isRunning(), true);
|
||||||
|
// for this moment should thick 4 times
|
||||||
|
assert.equal(sprite.frameIndex(), 4);
|
||||||
|
done();
|
||||||
|
}, 68);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
imageObj.src = 'assets/scorpion-sprite.png';
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user