kentasama
kentasama

Reputation: 11

kinecticjs - how to change Sprite frameRate

i have a 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
    });
.
.
.

with every Arrow Key press i am changing the troll animation using troll.setAnimation(newAnimation); (different animation for the each Arrow Key press).

i also want to change the frameRate, but i can't find a way to do it? (there is no "setFrameRate") is there any way to do it?

Upvotes: 0

Views: 183

Answers (2)

rpabon
rpabon

Reputation: 1201

There is indeed a method called setFrameRate (see here http://kineticjs.com/docs/Kinetic.Sprite.html).

The trick is to stop the sprite, set the new frame rate and animation and then start the sprite again. Using the code you provided, this would have to be added:

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

This code would have to be added inside the onload callback.

Upvotes: 1

SoluableNonagon
SoluableNonagon

Reputation: 11752

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.

Upvotes: 0

Related Questions