{"id":81,"date":"2008-11-04T00:00:18","date_gmt":"2008-11-04T07:00:18","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=67"},"modified":"2008-11-04T00:00:18","modified_gmt":"2008-11-04T07:00:18","slug":"2d-array-map","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=81","title":{"rendered":"2D Array Map"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar col:Array = &#x5B;0x000000, 0xCCCCCC, 0xFF0000, 0xCCCC00, 0x000055, 0x00CCCC];\r\n\r\nvar map:Array = new Array();\r\nmap&#x5B;0] = &#x5B;0,0,0,0,0,0,0,0,0,0];\r\nmap&#x5B;1] = &#x5B;0,0,0,0,0,0,0,0,0,0];\r\nmap&#x5B;2] = &#x5B;0,5,4,5,4,5,4,5,4,0];\r\nmap&#x5B;3] = &#x5B;0,4,4,4,4,4,4,4,4,0];\r\nmap&#x5B;4] = &#x5B;0,4,0,0,0,0,0,0,4,0];\r\nmap&#x5B;5] = &#x5B;0,3,2,3,2,3,2,3,2,0];\r\nmap&#x5B;6] = &#x5B;1,1,1,1,1,1,1,1,1,1];\r\nmap&#x5B;7] = &#x5B;0,2,2,2,2,2,2,2,2,0];\r\nmap&#x5B;8] = &#x5B;1,1,1,1,1,1,1,1,1,1];\r\n\r\nfor (var i:int = 0; i&lt;map.length; i++){\r\n\tfor (var j:int = 0; j&lt;map&#x5B;i].length; j++){\r\n\t\tgraphics.beginFill(col&#x5B;map&#x5B;i]&#x5B;j]]);\r\n\t\tgraphics.drawRect(j * 10, i * 10, 10, 10);\r\n\t}\r\n}\r\n<\/pre>\n<p>Use a 2D array to draw a map of colored rectangles. Lots of stuff you can do with this &#8211; like adding game tiles instead of drawing colored rects:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ add clip with multiple frames - each containing a tile graphic\r\nvar tile:MovieClip = TileClip();\r\ntile.gotoAndStop(map&#x5B;i]&#x5B;j]+1);\r\naddChild(tile);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>var col:Array = &#x5B;0x000000, 0xCCCCCC, 0xFF0000, 0xCCCC00, 0x000055, 0x00CCCC]; var map:Array = new Array(); map&#x5B;0] = &#x5B;0,0,0,0,0,0,0,0,0,0]; map&#x5B;1] = &#x5B;0,0,0,0,0,0,0,0,0,0]; map&#x5B;2] = &#x5B;0,5,4,5,4,5,4,5,4,0]; map&#x5B;3] = &#x5B;0,4,4,4,4,4,4,4,4,0]; map&#x5B;4] = &#x5B;0,4,0,0,0,0,0,0,4,0]; map&#x5B;5] = &#x5B;0,3,2,3,2,3,2,3,2,0]; map&#x5B;6] = &#x5B;1,1,1,1,1,1,1,1,1,1]; map&#x5B;7] = &#x5B;0,2,2,2,2,2,2,2,2,0]; map&#x5B;8] = &#x5B;1,1,1,1,1,1,1,1,1,1]; for (var i:int = 0; i&lt;map.length; i++){ for (var j:int = 0; j&lt;map&#x5B;i].length; j++){ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,33],"tags":[],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-arrays","category-graphics"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}