2012-05-27 51 views
1

作爲EaselJS的新手,我使用了與源zip文件一起打包的「Simple Sprite Sheet」示例中的代碼。我試圖讓一個精靈表加載和播放,但只有第一幀出現。使用EaselJS加載精靈表

function init() { 
    var stage = new Stage(document.getElementById("canvas")); 
    var ss = new SpriteSheet({ 
     "frames": { 
      "width": 159, 
      "numFrames": 71, 
      "regX": 0, 
      "regY": 0, 
      "height": 85 
     }, 
     "animations":{ 
      "instance1": [0, 0], 
      "images": ["./assets/spritesheet.png"] 
     }); 

    var animate = new BitmapAnimation(ss); 
    animate.x = 0; 
    animate.y = 0; 

    ss.getAnimation("instance1").frequency = 2; 
    ss.getAnimation("instance1").next = "instance1"; 
    animate.gotoAndPlay("instance1"); 


    stage.addChild(animate); 
    Ticker.setFPS(60); 
    Ticker.addListener(stage); 
} 

我不認爲我需要一個代碼的功能,因爲我沒有註冊任何事件,我只是從INSTANCE1打,框架和帆布都是大小相等的,如果我播放動畫通過用animate.play("instance1");代替animate.gotoAndPlay("instance1");,但循環。有什麼建議麼?提前致謝。

回答

2

我相信我在另一個網站上回答了這個問題。

問題是spritesheet格式是錯誤的。 「動畫」屬性是一個包含具有開始和結束幀的命名動畫的對象。在這個例子中,唯一動畫的開始和結束幀是[0,0],而「images」屬性位於動畫對象內部。正確的格式可以在這裏看到:

https://github.com/CreateJS/EaselJS/blob/master/examples/SimpleSpriteSheet.html

var ss = new SpriteSheet({ 
    "frames": { 
     "width": 159, 
     "numFrames": 71, 
     "regX": 0, 
     "regY": 0, 
     "height": 85 
    }, 
    "animations":{ 
     "instance1": [0, 25] // sample end frame is "25" 
    }, 
    "images": ["./assets/spritesheet.png"]); 
}); 

我希望幫助別人有同樣的問題。 乾杯,

+0

謝謝Lanny,我相信你回答了我在Google的EaselJS小組提出的問題。仍在試驗中,我在使用多個畫布和不同的FPS時遇到了另一個障礙,如果你能看一看,我會非常感激http://stackoverflow.com/questions/10861247/easeljs-having-two-canvases-with-different -fps – dcd0181