{"id":288,"date":"2009-05-18T13:11:20","date_gmt":"2009-05-18T20:11:20","guid":{"rendered":"https:\/\/actionsnippet.com\/?page_id=1391"},"modified":"2009-05-18T13:11:20","modified_gmt":"2009-05-18T20:11:20","slug":"quickbox2d-2","status":"publish","type":"page","link":"https:\/\/actionsnippet.com\/?page_id=288","title":{"rendered":"QuickBox2D"},"content":{"rendered":"<h2>Downloads<\/h2>\n<p>(recommended version)<br \/>\n<a href=\"https:\/\/actionsnippet.com\/qb2d\/QuickBox2D_1.1.zip\">QuickBox2D 1.1<\/a><\/p>\n<p>If you don&#8217;t already know, Box2D is a great physics library created by <a href=\"http:\/\/www.gphysics.com\/\">Erin Catto<\/a>. It was ported to AS3 by Matthew Bush and John Nesky. You can download the AS3 version of the library from the below link&#8230;<\/p>\n<p><a href=\"http:\/\/sourceforge.net\/projects\/box2dflash\/files\/box2dflash\/Box2DFlashAS3_2.0.2\/Box2DFlashAS3_2.0.2_.zip\/download\" target=\"blank\">Go Get Box2DFlashAS3 2.0.2<\/a>.<\/p>\n<p><b>WARNING: QuickBox2D currently only works with Box2DFlashAS3 2.0.2 and earliear versions, so be sure to download 2.0.2 (2.1a is still quite alpha from what I can tell).<\/b><\/p>\n<p>QuickBox2D is a mini-library I created to work with<a href=\"http:\/\/box2dflash.sourceforge.net\/\"> Box2DFlashAS3<\/a>. The main purpose of this library is to significantly simplify instantiation of rigid bodies and provide a simple way to skin rigid bodies with custom graphics. <\/p>\n<p>Additional features include:<br \/>\n<a href=\"https:\/\/actionsnippet.com\/?p=1471\">Polygon Triangulation<\/a><br \/>\n<a href=\"https:\/\/actionsnippet.com\/?p=1538\">FRIM (frame rate independent movement)<\/a><\/p>\n<p><em>(old versions)<\/em><br \/>\n<a href=\"https:\/\/actionsnippet.com\/qb2d\/QuickBox2D_v1.0.zip\">QuickBox2D 1.0<\/a><br \/>\n<a href=\"https:\/\/actionsnippet.com\/qb2d\/QuickBox2D_alpha108.zip\">QuickBox2D alpha 108<\/a><br \/>\n<a href=\"https:\/\/actionsnippet.com\/qb2d\/QuickBox2D_alpha_107.zip\">QuickBox2D alpha 107<\/a><br \/>\n<a href=\"https:\/\/actionsnippet.com\/qb2d\/QuickBox2D_alpha_106.zip\">QuickBox2D alpha 106<\/a><br \/>\n<a href=\"https:\/\/actionsnippet.com\/qb2d\/QuickBox2D_alpha_105.zip\">QuickBox2D alpha 105<\/a><\/p>\n<h2>Documentation<\/h2>\n<p>You&#8217;ll want to check out the QuickBox2D class and the QuickObject:<br \/>\n<a href=\"https:\/\/actionsnippet.com\/qb2d\/docs\/html\/index.html\" target=\"blank\">View the documentation<\/a><\/p>\n<h2>Examples<\/h2>\n<p>I&#8217;ve written a few posts that demo some of the features of QuickBox2D. <a href=\"https:\/\/actionsnippet.com\/?cat=113\">Check them out here.<\/a><\/p>\n<p>A tutorial is also in the works, but in the meantime once you&#8217;ve downloaded QuickBox2D and placed it in your classpath, you can try out some of these step by step snippets on your timeline&#8230; <\/p>\n<p>Simple example, creates a box and a circle:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\nsim.createStageWalls();\r\n\r\nsim.addBox({x:5, y:5, width:1, height:1});\r\nsim.addCircle({x:4, y:8, radius:2});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>More accurate collision detection for fast moving objects:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\nsim.createStageWalls();\r\n\r\n\/\/ turn on CCD for more accurate (and expensive) collision detection.\r\nsim.addBox({x:5, y:5, width:1, height:1, isBullet:true});\r\n\r\nsim.addCircle({x:4, y:8, radius:2});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>Easily change the color of rigid bodies:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\nsim.createStageWalls();\r\n\r\n\/\/ use QuickBox2D&#039;s simple renderer to change the color of rigid bodies\r\nsim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, fillColor:0xFFFF00});\r\n\r\nsim.addCircle({x:4, y:8, radius:2, fillColor:0xCC0000, fillAlpha:.5, lineThickness:3, lineAlpha:.5});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>The setDefault() method allows global changes to the default params argument:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\n\/\/ we can set default properties for all QuickObjects (now all objects will be green with no stroke)\r\nsim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});\r\n\r\nsim.createStageWalls();\r\n\r\nsim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});\r\n\r\nsim.addCircle({x:4, y:8, radius:2});\r\n\r\n\/\/ will use the new default radius of 1.5\r\nsim.addCircle({x:10, y:4, fillColor:0x666666});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>Static bodies (bodies that don&#8217;t move) are created by setting density to 0:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\n\/\/ we can set default properties for all QuickObjects\r\nsim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});\r\n\r\nsim.createStageWalls();\r\n\r\nsim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});\r\n\r\nsim.addCircle({x:4, y:8, radius:2});\r\n\r\n\/\/ will use the new default radius of 1.5\r\nsim.addCircle({x:10, y:4, fillColor:0x666666});\r\n\r\n\/\/ creating static bodies is done by setting density to 0\r\nsim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>Creating polygons:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\n\/\/ we can set default properties for all QuickObjects\r\nsim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});\r\n\r\nsim.createStageWalls();\r\n\r\nsim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});\r\n\r\nsim.addCircle({x:4, y:8, radius:2});\r\n\r\n\/\/ will use the new default radius of 1.5\r\nsim.addCircle({x:10, y:4, fillColor:0x666666});\r\n\r\n\/\/ creating static bodies is done by setting density to 0\r\nsim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});\r\n\r\n\/\/ polygon vertices must be defined from top to bottom and clockwise\r\nsim.addPoly({x:15, y:8, verts:&#x5B;&#x5B;0,0,2,2,0,2]], fillColor:0x0000FF});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>Creating complex polygons:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\n\/\/ we can set default properties for all QuickObjects\r\nsim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});\r\n\r\nsim.createStageWalls();\r\n\r\nsim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});\r\n\r\nsim.addCircle({x:4, y:8, radius:2});\r\n\r\n\/\/ will use the new default radius of 1.5\r\nsim.addCircle({x:10, y:4, fillColor:0x666666});\r\n\r\n\/\/ creating static bodies is done by setting density to 0\r\nsim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});\r\n\r\n\/\/ polygon vertices must be defined from top to bottom and clockwise\r\n\/\/ additional polygons can be added in the form of arrays. Each individual\r\n\/\/ poly must be convex and can only have up to 8 vertices\r\n\/\/ there is no limit to the number of polygons you can add - and combined polygons\r\n\/\/ can be used to create concave shapes\r\nsim.addPoly({x:15, y:8, verts:&#x5B;&#x5B;0,0,2,2,0,2], &#x5B;0,0,0,1,-2,-0.2]], fillColor:0x0000FF});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>Using debug draw mode:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nstage.frameRate = 60;\r\n\r\n\/\/ QuickBox2D can optionally take parameters for the world and rendering\r\n\/\/ by setting debug to true we can use the Box2D debug renderer\r\nvar sim:QuickBox2D = new QuickBox2D(this, {debug:true});\r\n\r\n\/\/ we can set default properties for all QuickObjects\r\nsim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});\r\n\r\nsim.createStageWalls();\r\n\r\nsim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});\r\n\r\nsim.addCircle({x:4, y:8, radius:2});\r\n\r\n\/\/ will use the new default radius of 1.5\r\nsim.addCircle({x:10, y:4, fillColor:0x666666});\r\n\r\n\/\/ creating static bodies is done by setting density to 0\r\nsim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});\r\n\r\n\/\/ polygon vertices must be defined from top to bottom and clockwise\r\n\/\/ additional polygons can be added in the form of arrays. Each individual\r\n\/\/ poly must be convex and can only have up to 8 vertices\r\n\/\/ there is no limit to the number of polygons you can add - and combined polygons\r\n\/\/ can be used to create convex shapes\r\nsim.addPoly({x:15, y:8, verts:&#x5B;&#x5B;0,0,2,2,0,2], &#x5B;0,0,0,1,-2,-0.2]], fillColor:0x0000FF});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Downloads (recommended version) QuickBox2D 1.1 If you don&#8217;t already know, Box2D is a great physics library created by Erin Catto. It was ported to AS3 by Matthew Bush and John Nesky. You can download the AS3 version of the library from the below link&#8230; Go Get Box2DFlashAS3 2.0.2. WARNING: QuickBox2D currently only works with Box2DFlashAS3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-288","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/pages\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"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=288"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/pages\/288\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}