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 is not a function。这是指线

Crafty.sprite("megamanx.gif", { 

我不明白的是,对我来说,它看起来与这条线完全相同(除了图像源)

Crafty.sprite("sprites_huntw.png", {

因此,我不明白为什么会出现错误。预先感谢您的帮助

4

1 回答 1

0

您正在尝试调用.reel()作为返回值的方法Crafty.sprite。但是 Crafty.sprite 不返回精灵实体——它创建一个组件,然后返回全局Crafty对象(以便您可以在 Crafty 上链接方法调用)。

因此,您需要将该组件添加到实体中以使用它,然后添加 SpriteAnimation 组件来定义卷轴。这是文档中的一个示例:

// 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]]);
于 2015-04-06T17:44:34.850 回答