gpt4 book ai didi

javascript - 如何用 Phaser 3 绘制多边形?

转载 作者:行者123 更新时间:2023-12-02 23:27:24 25 4
gpt4 key购买 nike

我正在尝试使用 Phaser 3 框架绘制一个简单的多边形形状。问题是:多边形没有显示。

var config = {
type:Phaser.AUTO,
width:800,
height:600,
scene: {
preload: preload,
create: create,
}
};

var game = new Phaser.Game(config);

var poly;
var graphics;

function preload() {}

function create() {

poly = new Phaser.Geom.Polygon();
poly.setTo([ new Phaser.Geom.Point(200, 100), new Phaser.Geom.Point(350, 100), new Phaser.Geom.Point(375, 200), new Phaser.Geom.Point(150, 200) ]);


graphics = this.add.graphics(0, 0);
graphics.fillPoints(poly.points, true);
}

我得到的错误是:“Phaser.Polygon 不是构造函数”,但我在有关 Phaser 的教程上看到了该代码。

编辑:我按照 PhotonStorm 的建议更改了代码,现在我没有收到错误,但多边形仍然没有出现。

EDIT2:通过在图形对象上调用 lineStyle 和 fillStyle 来解决。

graphics = this.add.graphics(0, 0);

graphics.lineStyle(5, 0xFF00FF, 1.0);
graphics.fillStyle(0xFFFFFF, 1.0);
graphics.fillPoints(poly.points, true);

最佳答案

它是Phaser.Geom.Polygon

Here is the docs page for it .

一个基本示例:

    var polygon = new Phaser.Geom.Polygon([
400, 100,
200, 278,
340, 430,
650, 80
]);

关于javascript - 如何用 Phaser 3 绘制多边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56676491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com