簡體   English   中英

Kinetic.js [如何停止一個精靈]

[英]Kinetic.js [How can I stop one sprite]

我從Kinetic.js開始,我的第一個應用程序運行良好,但是我找不到停止Sprite的方法……例如,我有一個Sprite,並且我想只“播放”一次Sprite,查看框架,最后一個是一個簡單的stop()。 我怎樣才能做到這一點? (在精靈的最后一個“幀”之后停止)。

這是我的代碼(針對該精靈):

    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';

提前致謝!

您可以使用afterFrame函數,它將使您能夠在特定幀之后觸發事件。

然后,您可以在第5幀之后調用stop() (您需要將其更新為精靈中有多少幀。)

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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM