在 Phaser 中将多边形添加到组中
Adding Polygon to a Group in Phaser
我正在使用 Phaser 2.5.0
我正在尝试将图形(多边形)添加到组中。请参考以下代码。
我遇到了两个 javascript 错误。
Uncaught TypeError: child.setStageReference is not a function phaser.js:14661
Uncaught TypeError: this.children[i].preUpdate is not a function phaser.js:33643
错误来自最后一行 this.wrongLocation.add(poly);
谁能告诉我错误的原因。
this.wrongLocation = this.add.group();
this.wrongLocation.enableBody = true;
x = 360;
y = 0;
var poly = new Phaser.Polygon([ new Phaser.Point(x+64, y), new Phaser.Point(x+131, y+33), new Phaser.Point(x+66, y+64), new Phaser.Point(x, y+32) ]);
graphics = this.gathis.add.graphics(0, 0);
graphics.beginFill(0xFF33ff);
graphics.drawPolygon(poly.points);
graphics.endFill();
this.wrongLocation.add(poly);
请注意,我可以使用类似的代码将精灵添加到组中,没有任何问题。感谢您的帮助
poly
是一个形状。您要添加 graphics
,这是一个显示对象:
this.wrongLocation.add(graphics);
我正在使用 Phaser 2.5.0
我正在尝试将图形(多边形)添加到组中。请参考以下代码。
我遇到了两个 javascript 错误。
Uncaught TypeError: child.setStageReference is not a function phaser.js:14661
Uncaught TypeError: this.children[i].preUpdate is not a function phaser.js:33643
错误来自最后一行 this.wrongLocation.add(poly);
谁能告诉我错误的原因。
this.wrongLocation = this.add.group();
this.wrongLocation.enableBody = true;
x = 360;
y = 0;
var poly = new Phaser.Polygon([ new Phaser.Point(x+64, y), new Phaser.Point(x+131, y+33), new Phaser.Point(x+66, y+64), new Phaser.Point(x, y+32) ]);
graphics = this.gathis.add.graphics(0, 0);
graphics.beginFill(0xFF33ff);
graphics.drawPolygon(poly.points);
graphics.endFill();
this.wrongLocation.add(poly);
请注意,我可以使用类似的代码将精灵添加到组中,没有任何问题。感谢您的帮助
poly
是一个形状。您要添加 graphics
,这是一个显示对象:
this.wrongLocation.add(graphics);