Posted By

withinmedianl on 02/22/11


Tagged

rectangle grid


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

walterlow
adrianparr
tuffstudio


DrawGrid


 / Published in: ActionScript 3
 

Draws a grid so you can see if your placement is good

  1. public function drawGrid(spacingX:Number = 10, spacingY:Number = 10, lineWidthX:Number = 1, lineWidthY:Number = 1):void
  2. {
  3. var stw:Number = stage.stageWidth;
  4. var sth:Number = stage.stageHeight;
  5.  
  6. var grid:Sprite = new Sprite;
  7. grid.graphics.lineStyle (lineWidthX, 0x000000, 1);
  8.  
  9. for(var i:Number = 0; i < stw / spacingX + lineWidthX; i += 1)
  10. {
  11. grid.graphics.moveTo(0, (-spacingX) + spacingX * i);
  12. grid.graphics.lineTo(stw, (-spacingX) + spacingX * i);
  13. }
  14.  
  15. grid.graphics.lineStyle (lineWidthY, 0x000000, 1);
  16. for(var j:Number = 0; j < sth / spacingY + lineWidthY; j += 1)
  17. {
  18. grid.graphics.moveTo((-spacingY) + spacingY * j, 0);
  19. grid.graphics.lineTo((-spacingY) + spacingY * j, sth);
  20. }
  21.  
  22. grid.graphics.endFill();
  23. addChild(grid);
  24. }

Report this snippet  

You need to login to post a comment.