2

I´m starting with Kinetic.js and I have my first app working perfectly, but I don´t find the way to stop sprites... for example, I have one sprite and I want to "play" that sprite just once, see the frames and in the last one, one simple stop(). How can I do that? (Stop after the last "frame" of the sprite).

Here´s my code (for that sprite):

    var myImage = new Image();
    myImage.onload = function() {
    var mySprite = new Kinetic.Sprite({
        x: 250,
        y: 40,
        width: 70,
        height: 109,
        image: myImage,
        animation: 'idle',
        animations: animations,
        frameRate: 5
    });
    layer1.add(mySprite);
    mySprite.start();
    };
    myImage.src = 'sheet2.png';

Thanks in advance!

4

1 回答 1

1

您可以使用该afterFrame功能,这将使您能够在特定帧之后触发事件。

例如,您可以stop()在第 5 帧之后调用。(您需要将其更新为精灵中有多少帧。)

mySprite.afterFrame(5, function(){
    mySprite.stop();
});

afterFrame您可以在以下两篇文章中看到使用的示例:

http://ramkulkarni.com/blog/sprite-animation-in-html5-canvas-with-kineticjs/ http://www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-sprite-tutorial/

于 2013-04-30T15:32:29.887 回答