Phaser 3 组 incX 不是函数
Phaser 3 group incX is not a function
遵循文档https://phaser.io/phaser3/api/group
我创建了一个 group
并尝试调用方法 incX
var group = this.add.group();
group.incX(10);
然后我得到 Uncaught TypeError: group.incX is not a function
事实上,当我将对象打印到控制台时:
console.log(group);
我没有在文档中看到此方法或其他方法。
难道我做错了什么?文档是否过时?
听起来很奇怪,phaser.io 上似乎并非所有 Phaser 3 信息都是最新的。您可以抓取 current documentation on PhotonStorm's GitHub 并在本地浏览(只需打开 docs
文件夹中的任何 html 文件)。
至于代码,假设您期望 .incX()
会增加组中每个精灵的 x
属性,这里有一种方法可以做到这一点:
let children = group.getChildren();
children.forEach((child) => {
if (child instanceof Phaser.GameObjects.Sprite) {
child.x += 10;
}
});
遵循文档https://phaser.io/phaser3/api/group
我创建了一个 group
并尝试调用方法 incX
var group = this.add.group();
group.incX(10);
然后我得到 Uncaught TypeError: group.incX is not a function
事实上,当我将对象打印到控制台时:
console.log(group);
我没有在文档中看到此方法或其他方法。 难道我做错了什么?文档是否过时?
听起来很奇怪,phaser.io 上似乎并非所有 Phaser 3 信息都是最新的。您可以抓取 current documentation on PhotonStorm's GitHub 并在本地浏览(只需打开 docs
文件夹中的任何 html 文件)。
至于代码,假设您期望 .incX()
会增加组中每个精灵的 x
属性,这里有一种方法可以做到这一点:
let children = group.getChildren();
children.forEach((child) => {
if (child instanceof Phaser.GameObjects.Sprite) {
child.x += 10;
}
});