Drawing a checker board pattern quickly with AS3

Today I needed to dynamically generate a checker board pattern in ActionScript 3. I couldn’t find any examples on how to do it so I made my own. Below is a snippet of code I wrote to draw it and its super fast! I used bitwise operators in the loops to speed it up and it can draw a 2000x2000px area in 10 milliseconds.

[cc lang=”actionscript3″]
// Box colour 1
var even:uint = 0xCCCCCC;

// Box colour 2
var odd:uint = 0x999999;

// Box size
var size:int = 10;

// number of boxes horizontally
var nH:int = stage.stageWidth / size;

// number of boxes vertically
var nV:int = stage.stageHeight / size;

// vars to be used in the loops
var clr:uint;
var i:uint;
var j:uint;

// loop vertical
for (i=0;i


Comments

One response to “Drawing a checker board pattern quickly with AS3”

  1. Thank for for that code..

    sir can you help me more on how to make actionscript for checkers game some legal move of that.. i dont know where do i start.

Leave a Reply