Jump to content

Adding Polygon to a Group


Recommended Posts

Hi All,

I am using Phaser 2.5.0

I am trying to add a graphics (polygon) to a group. Please see the below code for your reference.

I am getting below two javascript errors.

Uncaught TypeError: child.setStageReference is not a function phaser.js:14661 
Uncaught TypeError: this.children.preUpdate is not a function phaser.js:33643

The error is comming from the last line this.wrongLocation.add(poly);

Can some one please let me know what could be the reason for the error.

Please note that i can add a sprite to a group using similar code without any problem. Thanks for your help

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);


Also I try to add the graphics to the group as below code


I can't see the error but the overlap between a sprite and this graphic is not working with the below code

me.game.physics.arcade.overlap(me.taxiNE, me.wrongLocation, me.hitTheRoad);

Any help will highly appreciated 

Link to comment
Share on other sites

Phaser.Polygon (as well as Phaser.Circle, Phaser.Rectangle, etc) are not graphics objects. They can't be displayed on the screen. Thus, adding them to a group causes the error you see -- they can't have stage references, they don't have a meaningful preUpdate.

Graphics objects can't have physics on them. You can use a Graphics object to generate a texture for a Sprite which *can* have physics on it. Enabling physics for a group doesn't mean everything added to it will have physics, it means Sprites you create using the Phaser.Group.create and Phaser.Group.createMultiple method will have physics. Since Graphics objects can't have physics you can't check them for overlap, either.

You probably want a Sprite, basically.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...