首页 > 解决方案 > 未捕获的类型错误:无法读取未定义的属性“框架”-PHASER3

问题描述

我是移相器和游戏开发的新手,我正在尝试使用动画构建游戏。我试图加载精灵表和动画 - 但我不断收到这个错误:

phaser.js:73195 Uncaught TypeError: Cannot read property 'frame' of undefined
    at Animation.setCurrentFrame (phaser.js:73195)
    at Animation.updateFrame (phaser.js:73224)
    at Animation.load (phaser.js:54133)
    at AnimationManager.load (phaser.js:53129)
    at Animation.load (phaser.js:72733)
    at Animation.play (phaser.js:72833)
    at Scene.update ((index):168)
    at Systems.step (phaser.js:27164)
    at SceneManager.update (phaser.js:46776)
    at Game.step (phaser.js:109330)

该错误似乎与为 spritesheet 加载的帧有关。

这是精灵表的预加载(图像的尺寸:宽度=80,高度=16。共5帧):

this.load.spritesheet("animal", "assets/animals.png", { frameWidth: 16, frameHeight: 16 });

这是函数 create() 中的动画:

this.anims.create({
        key: "animate",
        frames: this.anims.generateFrameNumbers("animal", {starts:0, ends:5}),
        frameRate: 10,
        repeat: -1
        })

问题似乎与“框架”属性有关,所以我尝试记录:

console.log(this.anims.generateFrameNumbers("animal", {starts:0, ends:5}))

但只有一个空列表。

标签: javascriptphaser-framework

解决方案


推荐阅读