javascript - 如何使用 Phaser 3 绘制多边形?
问题描述
我正在尝试使用 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
。
一个基本的例子:
var polygon = new Phaser.Geom.Polygon([
400, 100,
200, 278,
340, 430,
650, 80
]);
推荐阅读
- javascript - react的输入值与dom不同步
- angular - 在Angular中将多个数据从父组件传递到子组件时出错
- sockets - 我在哪里可以获得 dart.io RawSocket 示例?
- javascript - 如何使用moment js获取不同格式的日期
- apache - CKAN - 使用带有 curl 和 Apache 基本身份验证的 API
- android - Exposing a single boolean shared preference to other apps
- python - Python logging: Can I pass arguments to a custom handler in json config file
- c# - add html content in existing docx file using openxml in C#
- android - 使用 proguard 时构建期间出现 GMS 错误
- google-my-business-api - 使用 Google My Business API 获取评论链接