{"id":271,"date":"2009-05-01T16:21:21","date_gmt":"2009-05-01T23:21:21","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1261"},"modified":"2009-05-01T16:21:21","modified_gmt":"2009-05-01T23:21:21","slug":"quickbox2d-chain","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=271","title":{"rendered":"QuickBox2D Chain"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this, {debug:true});\r\n\/\/ use the box2D default renderer (debug : true)\r\n\r\nsim.createStageWalls();\r\n\r\n\/\/ anchor\r\nvar pre:QuickObject = sim.addCircle({x:9, y:3, radius:.5, density:0});\r\n\r\n\/\/ create a chain of boxes\r\nfor (var i:int = 0; i&lt;12; i++){\r\n  var curr:QuickObject = sim.addBox({x:10 + i, y:3, width:.9, height:.9, angularDamping:1});\r\n\t\t\t\t\t\t\t\t\t                             \r\n  \/\/ currently always adds a b2DistanceJoint\r\n  sim.addJoint({a:pre.body, b:curr.body, \r\n\t\t\t               x1:9 + i, y1: 3, x2: 10 + i, y2:3, collideConnected:false});\r\n  pre = curr;\r\n}\r\n\r\n\/\/ add a circle, use CCD (isBullet)\r\nsim.addCircle({x:20, y:10, radius:1, isBullet:true});\r\n\r\n\/\/ start simulation\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>This snippet uses my QuickBox2D library to create a chain. QuickBox2D is a wrapper for<a href=\"http:\/\/box2dflash.sourceforge.net\/\"> Box2DFlashAS3<\/a> that greatly simplifies world setup, instantiation and graphical skinning of rigid bodies (more info on <a href=\"https:\/\/actionsnippet.com\/?p=1254\" target=\"blank\">yesterdays post<\/a>)&#8230;<\/p>\n<p>See the swf <a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/qb2d\/chain_example.html\" target=\"blank\">here<\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/qb2d\\\/chain_example.swf&quot;,&quot;title&quot;:&quot;chain example&quot;,&quot;width&quot;:800,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#ffffff&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: chain example<\/span><\/button><\/span>.<\/p>\n<p>Download Box2DFlashAS3 <a href=\"http:\/\/sourceforge.net\/projects\/box2dflash\" target=\"blank\">here<\/a><\/p>\n<p>Download QuickBox2D Alpha 104 <a href=\"https:\/\/actionsnippet.com\/qb2d\/QuickBox2D_alpha104.zip\">here<\/a><\/p>\n<p>See yesterdays post for additional information. I&#8217;m still in the process of writing some docs and possibly a tutorial for QuickBox2D&#8230; hopefully I&#8217;ll finish with that soon&#8230; <\/p>\n<p>If your somewhat familiar with Box2D and just want to just dig right in, the following scrap of information may help:<\/p>\n<p><code><br \/>\n\/\/ Methods of the QuickBox2D class, used for creating rigid bodies and joints<br \/>\naddCircle();<br \/>\naddBox();<br \/>\naddPoly();<br \/>\n\/\/ currently only creates b2DistanceJoints<br \/>\naddJoint();<\/code><\/p>\n<p>these function all take one parameter Object as their argument. The common parameter properties for rigid bodies are:<\/p>\n<p><code>\/\/ QuickBox2D simpleRender settings:<br \/>\nlineColor:0x000000<br \/>\nlineAlpha:1<br \/>\nlineThickness:0<br \/>\nfillColor:0xCCCCCC<br \/>\nfillAlpha:1<br \/>\n\/\/ wrapped Box2D properties<br \/>\nx:3<br \/>\ny:3<br \/>\ndensity:1<br \/>\nfriction:0.5<br \/>\nrestitution:0.2<br \/>\nangle: 0<br \/>\nlinearDamping:0<br \/>\nangularDamping:0<br \/>\nisBullet:false,<br \/>\nfixedRotation:false<br \/>\nallowSleep: true<br \/>\nisSleeping:false<br \/>\n\/\/ advanced use<br \/>\nmaskBits:0xFFFF<br \/>\ncategoryBits:1<br \/>\ngroupIndex:0<\/p>\n<p>\/\/and the specific param properties are:<br \/>\naddCircle() :  radius<br \/>\naddBox()   : width, height<br \/>\naddPoly()  : verts<\/p>\n<p>\/\/Joints have the following properties... not going to bother explaining these until I write the docs:<br \/>\naddJoint() : a, b, x1, x2, y1, y2<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; var sim:QuickBox2D = new QuickBox2D(this, {debug:true}); \/\/ use the box2D default renderer (debug : true) sim.createStageWalls(); \/\/ anchor var pre:QuickObject = sim.addCircle({x:9, y:3, radius:.5, density:0}); \/\/ create a chain of boxes for (var i:int = 0; i&lt;12; i++){ var curr:QuickObject = sim.addBox({x:10 + i, y:3, width:.9, height:.9, angularDamping:1}); \/\/ currently always adds a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13,12],"tags":[3,15,4,16],"class_list":["post-271","post","type-post","status-publish","format-standard","hentry","category-box2d","category-motion","category-quickbox2d","tag-actionscript","tag-box2d","tag-flash","tag-quickbox2d"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/271","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=271"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/271\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}