Drawing a better game field background

Tetris background game fields are often represented as a checkerboard, so let's try to obtain the same result.

The idea: Once we defined two different colors, we will paint even squares with one color, and odd squares with the other color.

The development: We have to modify the way generateField function renders the background:

private function generateField():void { var colors:Array=new Array("0x444444","0x555555");"); fieldArray = new Array(); var fieldSprite:Sprite=new Sprite(); addChild(fieldSprite); fieldSprite.graphics.lineStyle(0,0x000000); for (var i:uint=0; i<20; i++) { fieldArray[i]=new Array(); for (var j:uint=0; j<10; j++) { fieldArray[i][j]=0; fieldSprite.graphics.beginFill(colors[(j%2+i%2)%2]); ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.