Jump to content

Adding polygon to group


rishavs
 Share

Recommended Posts

Hi

 

I am trying to create a simple hex grid.

In my Game state, I have defined a layer.

 

Using a the Phaser.Polygon method, I am trying to create a hex and then add it to the layer

 BasicGame.Game.prototype = {
 
create: function () {

var gridLayer = this.add.group(); gridLayer.z = 1; drawHexagon(20, 20, 10, 0.5); function drawHexagon(x,y,size,scale) { var hexVertices = {}; for (i = 0; i < 6; i++) { angle = 2 * Math.PI / 6 * (i + 0.5); hexVertices['x' + i] = x + size * Math.cos(angle); hexVertices['y' + i] = y + size * Math.sin(angle); }; console.log(hexVertices); var hex = new Phaser.Polygon(hexVertices['x0'], hexVertices['y0'], hexVertices['x1'], hexVertices['y1'], hexVertices['x2'], hexVertices['y2'], hexVertices['x3'], hexVertices['y3'], hexVertices['x4'], hexVertices['y4'], hexVertices['x5'], hexVertices['y5'] ); console.log(hex); gridLayer.add(hex); };
}

Running it however gives me "Uncaught TypeError: undefined is not a function" error.

I am sure this is something to do with using groups. What am i doing wrong?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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