2015-04-04 22 views
1

我試圖用EaselJS動畫一個spritesheet,但我不斷收到一個未捕獲的錯誤類型動畫spritesheet:

不確定是不是在這條線的功能 -
bmpAnimation = new createjs.BitmapAnimation(spriteSheet);

這是我到目前爲止的代碼:麻煩EaselJS

// JavaScript Document 
window.onload = function(){ 

//Creating a new Stage instance, passing in our canvas element's ID. 
var stage = new createjs.Stage("canvas"), 

imgMonsterARun = new Image(); 
imgMonsterARun.src = "img/MonsterARun.png"; 

    var spriteSheet = new createjs.SpriteSheet({ 
     // image to use 
     images: [imgMonsterARun], 
     // width, height & registration point of each sprite 
     frames: {width: 64, height: 64, regX: 32, regY: 32}, 
     animations: {  
      walk: [0, 9, "walk"] 
     } 
    }); 

    // create a BitmapAnimation instance to display and play back the sprite sheet: 
    bmpAnimation = new createjs.BitmapAnimation(spriteSheet); 

    // start playing the first sequence: 
    bmpAnimation.gotoAndPlay("walk");  //animate 

    // set up a shadow. Note that shadows are ridiculously expensive. You could display hundreds 
    // of animated rats if you disabled the shadow. 
    bmpAnimation.shadow = new createjs.Shadow("#454", 0, 5, 4); 

    bmpAnimation.name = "monster1"; 
    bmpAnimation.direction = 90; 
    bmpAnimation.vX = 4; 
    bmpAnimation.x = 16; 
    bmpAnimation.y = 32; 

    // have each monster start at a specific frame 
    bmpAnimation.currentFrame = 0; 
    stage.addChild(bmpAnimation); 

    createjs.Ticker.setFPS(60); 
    createjs.Ticker.useRAF = true; 
    createjs.Ticker.addListener(window); 

     function tick() 
     {  
      // Hit testing the screen width, otherwise our sprite would disappear 
      if (bmpAnimation.x >= screen_width - 16) { 
       // We've reached the right side of our screen 
       // We need to walk left now to go back to our initial position 
       bmpAnimation.direction = -90; 
      } 

      if (bmpAnimation.x < 16) { 
       // We've reached the left side of our screen 
       // We need to walk right now 
       bmpAnimation.direction = 90; 
      } 

      // Moving the sprite based on the direction & the speed 
      if (bmpAnimation.direction == 90) { 
       bmpAnimation.x += bmpAnimation.vX; 
      } 
      else { 
       bmpAnimation.x -= bmpAnimation.vX; 
      } 

      // update the stage: 
      stage.update(); 
     } 
     tick(); 

}; 

任何幫助,將不勝感激。

+0

解決了這個問題!版本0.8.0不支持BitmapAnimation必須使用0.6.0 – jordan 2015-04-04 22:05:31

回答

1

嘗試使用「雪碧」而不是「BitmapAnimation」。

也就是說

bmpAnimation = new createjs.BitmapAnimation(spriteSheet); 

成爲

bmpAnimation = new createjs.Sprite(spriteSheet); 

爲我工作。