Jump to content

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();
Link to comment
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.

Link to comment
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


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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