Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Submitted by Ryan Clark (W3Geek) */
- /* Link to post: http://redd.it/1aw8am */
- /* These variables are used to calculate
- * how many times the for loops execute,
- * height and width of each object on
- * every loop. */
- var numrows:uint = 10;
- var numcols:uint = 10;
- var rowheight:uint = 32;
- var colwidth:uint = 32;
- /* No sense declaring the variables over
- * and over inside the nested for loop. */
- var curX:uint = 0;
- var curY:uint = 0;
- /* The meat of the code. The outer for
- * loop executes causing the inner for
- * loop to execute 'numcol' times. Once
- * the inner for loop finishes, the outer
- * loop checks to see if it needs to be
- * executed again... */
- for (i = 0; i < numrows; i++) {
- for (j = 0; j < numcols; j++) {
- /* Use curX and curY to place your objects */
- // ...
- curX += colwidth;
- }
- curY += rowheight;
- curX = 0; // reset the X location (since we're going to the next row)
- }
- /* Some output of using this algorithm. */
- /* First Loop
- /* Inner Loop
- * Loop 1: curX = 0, curY = 0
- * Loop 2: curX = 32, curY = 0
- * Loop 3: curX = 64, curY = 0
- * Loop 4: curX = 96, curY = 0
- * Loop 5: curX = 128, curY = 0
- * Loop 6: curX = 160, curY = 0
- * Loop 7: curX = 192, curY = 0
- * Loop 8: curX = 224, curY = 0
- * Loop 9: curX = 256, curY = 0
- * Loop 10: curX = 288, curY = 0
- * Now you can kinda picture what this does to yourself. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement