Kinetic.js [如何停止一个精灵] [英] Kinetic.js [How can I stop one sprite]
问题描述
我从Kinetic.js开始,我的第一个应用程序运行良好,但是我找不到停止子画面的方法...例如,我有一个子画面,我想播放"该子画面仅查看一次框架,最后一个查看一个简单的stop().我怎样才能做到这一点? (在精灵的最后一个帧"之后停止.)
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';
提前谢谢!
推荐答案
You can use the afterFrame
function, which will enable you to trigger an event after a specific frame.
然后,您可以在例如第5帧之后调用stop()
. (您需要将其更新为精灵中的帧数为多.)
Then you can call stop()
after frame 5, for example. (you'll need to update this to however many frames there are in your sprite.)
mySprite.afterFrame(5, function(){
mySprite.stop();
});
您可以在以下两个帖子中看到使用afterFrame
的示例:
You can see an example of the use of afterFrame
in the following two posts:
http://ramkulkarni.com/blog/sprite -animation-in-html5-with-kineticjs/ http://www.html5canvastutorials.com/kineticjs/html5-canvas- eticjs-sprite-tutorial/
这篇关于Kinetic.js [如何停止一个精灵]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!