{"id":302,"date":"2009-05-31T16:27:54","date_gmt":"2009-05-31T23:27:54","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1479"},"modified":"2009-05-31T16:27:54","modified_gmt":"2009-05-31T23:27:54","slug":"quickbox2d-groups","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=302","title":{"rendered":"QuickBox2D Groups"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\n&#x5B;SWF (backgroundColor=0xAA0000, width=700, height=600, frameRate=60)]\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\nsim.createStageWalls();\r\n\r\n\/**\r\ncreate a dancing pill\r\n*\/\r\n\/\/ all x and y coords are relative to the center of the group\r\nvar partA:QuickObject = sim.addCircle({x:-1, y:0, radius:0.5, restitution:.9});\r\nvar partB:QuickObject = sim.addCircle({x:1, y:0, radius:0.5, restitution:.9});\r\nvar partC:QuickObject = sim.addBox({x:0, y:0, width:2, height:1});\r\n\/\/ all the parts are passed into the objects array\r\n\/\/ addGroup() groups the parts together into one rigid body\r\nvar pill:QuickObject = sim.addGroup({objects:&#x5B;partA, partB, partC], x:3, y:3, angle:0.3});\r\n\r\n\/**\r\ncreate another group\r\n*\/\r\npartA = sim.addCircle({x:0, y:0, radius:1});\r\npartB = sim.addBox({x:0, y:1, width:1, height:1, fillColor:0x666666});\r\npartC = sim.addBox({x:0, y:-1, width:1, height:1, fillColor:0x666666});\r\nsim.addGroup({objects:&#x5B;partA, partB, partC], x:8, y:3, angle:0.3});\r\n\r\n\/**\r\ncreate two circles linked together by a stretchy joint\r\n*\/\r\npartA = sim.addCircle({x:15, y:3, fillColor:0x000000, anglularDamping:1});\r\npartB = sim.addCircle({x:17, y:3, fillColor:0xFFFFFF, anglularDamping:1});\r\n\/\/ if x1, y1, x2 and y2 properties are not set, the joint is automatically placed\r\n\/\/ at the b2Body&#039;s center\r\nsim.addJoint({a:partA.body, b:partB.body, frequencyHz:1});\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>You&#8217;ll need <a href=\"https:\/\/actionsnippet.com\/?page_id=1391\" target=\"blank\">QuickBox2D Alpha 106<\/a> to run this&#8230; This snippet demo&#8217;s the addGroup() method, which allows for easy grouping of shapes. I updated <a href=\"https:\/\/actionsnippet.com\/qb2d\/docs\/html\/index.html\" target=\"blank\">the docs<\/a> today to feature a simple explanation of how this works. <\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/groups_and_joints.html\" target=\"blank\"><br \/>\nHave a look at the swf here&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/qb2d_groups.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/groups_and_joints.swf&quot;,&quot;title&quot;:&quot;groups and joints&quot;,&quot;width&quot;:700,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#aa0000&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: groups and joints<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; &#x5B;SWF (backgroundColor=0xAA0000, width=700, height=600, frameRate=60)] var sim:QuickBox2D = new QuickBox2D(this); sim.createStageWalls(); \/** create a dancing pill *\/ \/\/ all x and y coords are relative to the center of the group var partA:QuickObject = sim.addCircle({x:-1, y:0, radius:0.5, restitution:.9}); var partB:QuickObject = sim.addCircle({x:1, y:0, radius:0.5, restitution:.9}); var partC:QuickObject = sim.addBox({x:0, y:0, width:2, height:1}); \/\/ [&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],"class_list":["post-302","post","type-post","status-publish","format-standard","hentry","category-box2d","category-motion","category-quickbox2d","tag-actionscript","tag-box2d","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/302","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=302"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/302\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}