Hightower Posted March 27, 2014 Share Posted March 27, 2014 Hi, I have a grid of buttons ie: B | B | BB | B | BB | B | B I would like to get these in an array so I can run checks against them and surrounding buttons, but whenever I do something like:button[x][y] = game.add.button(...)My game just has a black screen, where asbutton = game.add.button(...)works fine. The reason I thought of putting them in an array is so say you click on 0,0 I can then check the status (and change the texture if needed) of 0,1 Can anybody help? Thanks, Link to comment Share on other sites More sharing options...
drhayes Posted March 27, 2014 Share Posted March 27, 2014 This might be a dumb suggestion... but how are you constructing the 2d array before adding the buttons to it? Try something like this:var buttons = [];for (var rowIndex = 0; rowIndex < numRows; rowIndex++) { var row = []; for (var colIndex = 0; colIndex < numCols; colIndex++) { row.push(game.add.button(...)); } buttons.push(row);} Link to comment Share on other sites More sharing options...
Hightower Posted March 27, 2014 Author Share Posted March 27, 2014 This might be a dumb suggestion... but how are you constructing the 2d array before adding the buttons to it? Try something like this:var buttons = [];for (var rowIndex = 0; rowIndex < numRows; rowIndex++) { var row = []; for (var colIndex = 0; colIndex < numCols; colIndex++) { row.push(game.add.button(...)); } buttons.push(row);} That seems to have done it thanks. Will take a look at how to make it all fit tomorrow now. Link to comment Share on other sites More sharing options...
Recommended Posts