I'm stuck trying to get each grid square's properties through an array. My goal is to give each grid square a name location and call it by a name, but stuck at just at trying to call each grid through an array.
I thought I could push rectangle into an array and use a for loop to call each grid by this. Then, start to mess with other properties.
Calling the rectangle with an array does not work, but calling the rectangle graphic does. Having trouble troubleshooting this.
Below is my gridSetUp function.
function gridSetUp(){
var row;
var col;
var rowArr;
var colArr;
var fullGridRowArr = [];
var fullGridColArr = [];
var rowLength = 5;
var colLength = 5;
for(row = 0; row < rowLength; row++){
for(col = 0; col < colLength; col++){
var fullGridRect = new PIXI.Graphics();
fullGridRect.beginFill(0xffffff, 0.25);
fullGridRect.lineStyle(0.5, 0xFF0000, 1);
fullGridRect.interactive = true; // new
fullGridRect.hitArea = new PIXI.Rectangle(0, 0, 30, 30);
fullGridRect.drawRect(0, 0, 30, 30);
fullGridRect.endFill();
fullGridRect.x = (fullGridRect.width + fullGridRect.x) * col;
fullGridRect.y = (fullGridRect.height + fullGridRect.y) * row;
fullGridRect.alpha = 0.5;
stage.addChild(fullGridRect);
fullGridRowArr.push(row);
fullGridColArr.push(col);
// Works with shape by itself, but not when shape is pushed into array.
// Make full grid interactive
fullGridRect.interactive = true;
fullGridRowArr.interactive = true;
fullGridRowArr.click = function(mouseData){
//console.log('ROW : MOUSE CLICK SHAPE');
console.log(this.fullGridRowArr[row]);
};
/* THIS WORKS BUT NOT THE ABOVE
fullGridRect.click = function(mouseData){
console.log('MOUSE CLICK SHAPE');
};
*/
}
}
//Start the game loop
gameLoop();
}