2015-04-06 20 views
0
if (char == 'anime') { 
     Crafty.sprite("sprites_hunt_w.png", { 
       guy: [1, 2, 27, 31] 
      }) 
      .reel('guy_right', 1000, [ 
       [1, 64], 
       [34, 64], 
       [65, 65] 
      ]) 
      .reel('guy_left', 1000, [ 
       [1, 32], 
       [34, 32], 
       [65, 33] 
      ]) 
    } else { 
     Crafty.sprite("megamanx.gif", { 
       guy: [0, 0, 28, 34] 
      }) 
      .reel('guy_right', 1000, [ 
       [214, 19], 
       [248, 19], 
       [281, 19], 
       [321, 19], 
       [352, 19], 
       [371, 19], 
       [394, 19], 
       [427, 19] 
      ]) 
      // }else{ 
      //console.log("fail") 
    } 

firefox的控制檯說TypeError:Crafty.sprite(...)。reel不是一個函數。這指的是線路Crafty JS錯誤說我沒有關閉功能

Crafty.sprite("megamanx.gif", { 

我不明白的事情是,對我來說,它看起來(比圖像源等)完全一樣,這條線

Crafty.sprite("sprites_huntw.png", { 

因爲這個,我不要的」不明白爲什麼我會得到錯誤。預先感謝您的幫助

+0

'console.log(Crafty.sprite)'' – zerkms 2015-04-06 03:08:56

回答

0

您試圖撥打.reel()作爲返回值Crafty.sprite的方法。但Crafty.sprite不會返回一個精靈實體 - 它會創建一個組件,然後返回全局對象(以便您可以將方法調用鏈接到Crafty上)。

因此,您需要將該組件添加到實體以使用它,然後添加SpriteAnimation組件以定義卷軸。這裏有一個來自the docs的例子:

// Define a sprite-map component 
Crafty.sprite(16, "images/sprite.png", { 
    PlayerSprite: [0,0] 
}); 

// Define an animation on the second row of the sprite map (fromY = 1) 
// from the left most sprite (fromX = 0) to the fourth sprite 
// on that row (frameCount = 4), with a duration of 1 second 
Crafty.e("2D, DOM, SpriteAnimation, PlayerSprite").reel('PlayerRunning', 1000, 0, 1, 4); 

// This is the same animation definition, but using the alternative method 
Crafty.e("2D, DOM, SpriteAnimation, PlayerSprite").reel('PlayerRunning', 1000, [[0, 1], [1, 1], [2, 1], [3, 1]]);