# Polygon use variables?

## Recommended Posts

Tried to create new polygon without success if using x, y as a variables in place of numbers. How do I use variables?

`	var g = game.add.graphics(0,0);	var poly = new Phaser.Polygon();	var aa = new Array;	aa.push(new Phaser.Point(x,y))	aa.push(new Phaser.Point(x,y1))	aa.push(new Phaser.Point(x1,y1))	aa.push(new Phaser.Point(x,y1))    	poly.setTo(aa);	    g.beginFill(0xFF33ff);    g.drawPolygon(poly.points);    g.endFill();`
##### Share on other sites

What does "without success" mean? Were you seeing errors in the JavaScript console? What were they? What are the values of x, y, x1, and y1?

##### Share on other sites

What does "without success" mean? Were you seeing errors in the JavaScript console? What were they? What are the values of x, y, x1, and y1?

x, y, x1, y1 are numbers e.g. x=100

It wasn't visible on the world unless I have replaced it with the 4 variables with numbers. There is no error.

##### Share on other sites

http://phaser.io/examples/v2/geometry/polygon#gv

Lines 40:

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

with using new Phaser.Point(x,y)

##### Share on other sites

Don't know if this is causing the bug but you're giving twice the same set of coords :

`aa.push(new Phaser.Point(x,y))aa.push(new Phaser.Point(x,y1))  // Hereaa.push(new Phaser.Point(x1,y1))aa.push(new Phaser.Point(x,y1))  // And there`

Shouldn't it be :

`aa.push(new Phaser.Point(x,y))aa.push(new Phaser.Point(x,y1))aa.push(new Phaser.Point(x1,y1))aa.push(new Phaser.Point(x1,y))  // <- Change`