javascript - 未捕获的类型错误:无法读取未定义的属性“框架”-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}))
但只有一个空列表。
解决方案
推荐阅读
- php - 如何在 MySQL 数据库中插入具有多个值的输入?
- css - 为什么我的图像网格不显示四列?
- c# - 为什么动态转换比对象快
- django - 如何查询当前对象之外的模型实例
- jquery - 印地语 jQuery 测验未显示正确答案
- javascript - Firebase 功能 auth user onCreate uni 测试
- rest - 使用自定义错误结构和结构验证实现错误处理?
- tensorflow - 如何在每个时代结束时用 tf.keras 拟合和评估 tf.data.dataset?
- c++ - 模板类外部长定义的替代方案
- javascript - 使用 OnClick 方法更改循环图像源