简体   繁体   中英

kineticjs tween: continue code after tween finished

how do I have to change the code that I get the last two lines after the tween finished? At this moment I get the last two log, the sound plays and at same time the tween start. And while the sound is playing the teen finished and I get the last log ("tween finished").

var tween = new Kinetic.Tween({
            node: mynode, 
            duration: 100,
            x: 100,
            y: 200,
            scaleX: 80,
            scaleY: 80,
            onFinish: function() {
                console.log("Tween finished");
            }
});
tween.play();
//The next lines should be executed after the onFinish-event
console.log("This should be the first log");
console.log("Executed before 'Tween finished'");
.. do something e.g. play a sound

Just put it in another function and call it from within onFinish:

var func2 = function() {
    console.log("This should be the first log");
    console.log("Executed before 'Tween finished'");
    // .. do something e.g. play a sound
}

var tween = new Kinetic.Tween({
        node: mynode, 
        duration: 100,
        x: 100,
        y: 200,
        scaleX: 80,
        scaleY: 80,
        onFinish: function() {
            console.log("Tween finished");
            func2();
        }
});
tween.play();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM