首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到Phaser 3 Phaser.GameObjects.Sprite正文

找不到Phaser 3 Phaser.GameObjects.Sprite正文
EN

Stack Overflow用户
提问于 2019-09-30 20:46:54
回答 2查看 398关注 0票数 0

我不熟悉phaser 3

当我扩展sprite时

它没有这样的属性

但我肯定它有这样的特性

尽管终端显示错误

这个游戏在网络上运行仍然很好

以下是我的代码

代码语言:javascript
复制
export class Planet2 extends Phaser.GameObjects.Sprite {
    cellWidth: number;
    cellHeight: number;


    constructor(config) {
        super(config.scene, config.x, config.y, 'planet2');

        config.scene.physics.world.enable(this);
        config.scene.add.existing(this);

        this.body.allowGravity = false;

        this.cellWidth = config.scene.cameras.main.width / 100;

        this.body.moves = true;
        this.body.offset.x = this.cellWidth * 2;
        this.body.setSize(this.cellWidth * 8, this.cellWidth * 8, 0, 0);
        this.body.isCircle = true;


    }


}

和github在这里https://github.com/lalalalaluk/ion-phaser-test.git

非常感谢!

EN

回答 2

Stack Overflow用户

发布于 2020-05-05 05:52:07

你扩展了一个错误的类用于启用了物理的精灵,这就是为什么你在body属性上得到一个类型错误的原因。尝试使用Phaser.Physics.Arcade.Sprite for Arcade physics Phaser.Physics.Matter.Sprite for Matter。

票数 1
EN

Stack Overflow用户

发布于 2020-10-04 22:48:17

也许有点晚了,只是遇到了同样的问题,我需要包装到一个类中,并键入它才能正常工作。对我来说,我使用的是Arcade物理。

代码语言:javascript
复制
class Planet2 extends Phaser.GameObjects.Sprite {
    body: Phaser.Physics.Arcade.Body;

    constructor(scene, x = 0, y = 0, key = '') {
        super(scene, x, y, key);

        scene.physics.world.enableBody(this);
        this.body.setAllowGravity(false);
        scene.add.existing(this);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58168244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档