I found several ways to do this but no one was very detailed, basically they all just said "copy and paste my awesome code and watch the magic happen".
well with as3 this can be achieved by using the for loop 2 times, once for the rows and again for the columns
if you wanted a chessboard make 1 black square with the instance name of tileSquare example:
//how many tiles in row and column private var rows:Number = 8; private var columns:Number = 8;
//empty movieclip with tile private var board:MovieClip = new MovieClip(); private var tile:tileSquare = new tileSquare(); function main():void { //add the empty movieclip board = new MovieClip(); addChild(board);
well with as3 this can be achieved by using the for loop 2 times, once for the rows and again for the columns
if you wanted a chessboard make 1 black square with the instance name of tileSquare example:
//how many tiles in row and column private var rows:Number = 8; private var columns:Number = 8;
//empty movieclip with tile private var board:MovieClip = new MovieClip(); private var tile:tileSquare = new tileSquare(); function main():void { //add the empty movieclip board = new MovieClip(); addChild(board);
//for loop rows for(var rows:int=0;rows<8;rows++) { //for loop columns for(var columns:int=0;columns<8;columns++) { //check if odd then even if(numParity(rows) == "odd" && numParity(columns) == "even" { //add tile tile = new tileSquare(); tile.x = rows*tile.width+tile.width*.5; tile.y = columns*tile.height+tile.height*.5; board.addChild(tile); } //check again but if even then odd else if(numParity(rows) == "even" && numParity(columns) == "odd" { //add tile tile = new tileSquare(); tile.x = rows*tile.width+tile.width*.5; tile.y = columns*tile.height+tile.height*.5; board.addChild(tile); } } } } //check if even or odd function function numParity(num:Number):String { var parity:String = new String(); num % 2 ? parity = "odd" : parity = "even"; return parity; }
at that point you can reference any tile by checking the row and column values
The even/odd function returns weather the row and column is even or odd which I used simply to check for alternating tiles. So yes it is extra just to determine the placement of the black tiles
this is not the best look at it but it gives you an idea of what is going on
the first box is 1, 1 making it odd, odd. the one next to it on the right is 1, 2 making it odd, even
if you used my system you can simply just create a new MoveClip then check for the desired odd or even combination and add the MovieClip similar toadding the black tile
I'm not getting it, I mean, I understand even odd stuff, just not how I should go about doing this with your code.
I've tried copy and pasting the for loop that has "even" and "odd" inside them and messing with the combinations where even and odd are, but nothing is working. Also tried changing the placement of them where it multiplies by .5 to 1, 2, .25, and also tried messing with when it +'s the height and width by its own height and width.
Sorry for wasting your time, but I've gone thru all my ideas and need some more help.