javascript - 在 EaselJS 中为 spritesheet 设置动画时出现问题

标签 javascript html canvas easeljs sprite-sheet

我正在尝试使用 EaselJS 为 spritesheet 设置动画,但我一直收到未捕获的类型错误:

undefined is not a function on this line -
bmpAnimation = new createjs.BitmapAnimation(spriteSheet);

到目前为止,这是我的代码:

// 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.8.0 中,您可以使用普通的 SpriteSheet 创建动画 SpriteSheet。在 http://createjs.com/Demos/EaselJS/SpriteSheet 上查看演示(确保检查“实时编辑”下的代码;-))

关于javascript - 在 EaselJS 中为 spritesheet 设置动画时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29450956/

相关文章:

javascript - 带有结果和参数的 FileReader 加载

wpf - 如何强制滚动条滚动 Canvas

javascript - 使用 jQuery 将 div 定位到屏幕外的右侧

javascript - TypeError : user. 保存不是函数 [mongoose]

javascript - 仅在 Safari 中发生的 XHR 请求的 DOM 异常 11

html - 将文本添加到页面顶部,而不会将页面的其余部分向下推

java - 检查 Thymeleaf 中的 If-Else

javascript - 如何从 perl 脚本发送准备显示的 html?

javascript - 如何使用 Canvas 创建半水滴和半砖图案

python - 删除以前的输出 tkinter