JesusJoseph Posted June 26, 2016 Share Posted June 26, 2016 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); graphics.beginFill(0xFF33ff); graphics.drawPolygon(poly.points); graphics.endFill(); this.wrongLocation.add(poly); Also I try to add the graphics to the group as below code me.wrongLocation.add(graphics); 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 More sharing options...
drhayes Posted June 27, 2016 Share Posted June 27, 2016 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 More sharing options...
JesusJoseph Posted June 27, 2016 Author Share Posted June 27, 2016 Thanks for your info. I will try to create a sprite from the Graphics that I create and try to get the physics object Link to comment Share on other sites More sharing options...
Recommended Posts