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
Leave a Reply
You must be logged in to post a comment.