[英]In Kinetic.js how can I load multiple images with one image loaded on canvas at a time
[英]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.