0

我有一个 Kinetic.Sprite obj:

//create troll obj:
var trollImageObj = new Image();
trollImageObj.onload = function () {
    var troll = new Kinetic.Sprite({
        x: 250,
        y: 40,
        image: trollImageObj,
        animation: 'solid_down',
        animations: animations,
        frameRate: 2
    });
.
.
.

每次按下箭头键时,我都会troll使用troll.setAnimation(newAnimation);(每个箭头键按下不同的动画)更改动画。

我也想换frameRate,可是找不到方法?(没有“setFrameRate”)有什么办法吗?

4

2 回答 2

1

确实有一种方法称为setFrameRate(参见此处http://kineticjs.com/docs/Kinetic.Sprite.html)。

诀窍是停止精灵,设置新的帧速率和动画,然后再次启动精灵。使用您提供的代码,必须添加:

   troll.stop();
   troll.setAnimation('newAnimation');
   troll.setFrameRate(10); // 10 as an example
   troll.start();

必须在onload回调中添加此代码。

于 2013-12-28T19:54:18.987 回答
0

well, you can try just accessing the {config} attributes directly:

  trollImageObj.attrs.frameRate = some number;

but I don't think that will work; I think the object animation is not modifiable after you create it.

The thing to do would be either to create separate sprites for your different animations, or to add/remove animation frames to your animation.

于 2013-03-19T15:52:52.173 回答