Hey everyone So I have created a grid on stage using the code below. Everything works fine and the grid is created. Only problem is when i change the columns and rows value to a higher value the grids position changed offset to the center of the stage. I want it to be when i change the values and more columns etc are added the Grid stays dead center.
Also it seems that the grid expands to the positive x axis from the top left hand corner of the grid.
What can I do to fix this?
public function geniusMatchEngine()
{
//Instantiate Variables
nSquares = 0;
//Movie clips
_gridContainer = new MovieClip();
stage.addChild(_gridContainer);
createGrid();
//Add Listeners
stage.addEventListener(Event.ENTER_FRAME, logicHandler);
}
private function logicHandler(e:Event):void
{
}
private function createGrid():void
{
for (var gy:int = 0; gy < rows; gy++)
{
for (var gx:int = 0; gx < columns; gx ++)
{
var _grid:mcGrid = new mcGrid();
_grid.x = (stage.stageWidth / 2) + _grid.width * gx;
_grid.y = (stage.stageHeight / 2) + _grid.height * gy;
_gridContainer.addChild(_grid);
_grid.addEventListener(MouseEvent.CLICK, tapGrid);
}
}
}
private function tapGrid(e:MouseEvent):void
{
trace("CLICKED");
e.currentTarget.destroy(); //Destroy current target
}
private function centerGrid(gCenter:MovieClip):void
{
gCenter.x = (stage.width / 2) - (gCenter.width / 2); // center horizontally.
gCenter.y = (stage.height / 2) - (gCenter.height / 2); // center vertically.
}