{"id":401,"date":"2009-09-10T12:34:21","date_gmt":"2009-09-10T19:34:21","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2142"},"modified":"2009-09-10T12:34:21","modified_gmt":"2009-09-10T19:34:21","slug":"quickbox2d-vaguely-goldberg-esque","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=401","title":{"rendered":"QuickBox2D Vaguely Goldberg-esque"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\nimport Box2D.Common.Math.*;\r\nimport Box2D.Collision.Shapes.*;\r\n\r\n&#x5B;SWF(width = 800, height = 600, backgroundColor = 0xFFFFFF, frameRate=60)]\r\n\r\n\/\/ hide everything for 300 ms\r\nvisible = false;\r\nsetTimeout(function():void{ visible = true}, 300);\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this, {debug:false});\r\n\r\nsim.setDefault({fillColor:0x666666, lineAlpha:0})\r\nsim.createStageWalls();\r\n\r\nmakeLever(6 , 17.5, 9, &quot;right&quot;, 0.7);\r\n\r\nvar circleA:QuickObject = sim.addCircle({x:2, y:3, radius:0.5, mass:4});\r\n\r\nsim.addBox({x:15, y:12, width:2, height:0.5, density:0})\r\n\r\nsim.addCircle({x:16, y:11, radius:0.5, mass:4, friction:0.2, fillColor:0});\r\n\r\nsim.addBox({x:20.5, y:12, width:2, height:0.3, angle:-0.6, restitution:4.6, density:0})\r\n \r\nmakeLever(20 , 17.5, 8, &quot;right&quot;, 1);\r\n \r\nsim.addBox({x:9, y:9, width:2, height:0.5, density:0});\r\n\r\nsim.addCircle({x:9, y:9, radius:0.5, mass:4, friction:0.2, fillColor:0});\r\n\r\nsim.addBox({x:7, y:12, width:2, height:0.5, angle:-0.3, density:0, restitution:2});\r\n\r\nsim.addBox({x:3, y:7, width:2, height:0.5, angle:Math.PI\/2 - 0.22, density:0, restitution:3});\r\n\r\nsim.addBox({x:13, y:15, width:2, height:0.5, density:0, angle:0.3, restitution:1});\r\n\r\nsim.addBox({x:25.5, y:7, width:2, height:0.3, angle:-0.2, restitution:0.5, density:0})\r\n\r\nsim.addBox({x:26, y:10, width:1, height:1, density:0,restitution:0.3});\r\n\r\nsim.addBox({x:25, y:19, width:2, height:0.5, density:0, restitution:3.5, angle:-0.99});\r\n\r\nsim.addBox({x:1, y:17, width:0.3, height:2, density:0, angle:-0.15, restitution:0.999});\r\n\r\nsim.addBox({x:0.7, y:11, width:0.3, height:2, density:0, angle:-0.19, restitution:20})\r\n\r\nsim.addBox({x:0.4, y:11.5, width:1, height:0.3, density:0})\r\n\r\nfunction makeLever(xp:Number, yp:Number, boxWidth:Number, dir:String, off:Number=0, hasBox:Boolean=true):QuickObject{\r\n\tvar angle:Number, xpos:Number, weight:QuickObject\r\n\tif (dir == &quot;right&quot;){\r\n\t\tangle = 0.43;\r\n\t\txpos = xp + boxWidth \/ 2 - off;\r\n\t}else{\r\n\t\tangle = -0.43;\r\n\t\txpos = xp - boxWidth \/ 2 + off;\r\n\t}\r\n\t\r\n\tif (hasBox){\r\n\t  weight = sim.addBox({x:xpos , y:yp, width:0.5, height:0.5, angle:angle, fillColor:0});\r\n\t}\r\n\r\n\tvar plank:QuickObject = sim.addBox({x:xp, y:yp, width:boxWidth, height:0.5, angle:angle});\r\n\tvar fulcrum:QuickObject = sim.addPoly({x:xp, y:yp, verts:&#x5B;&#x5B;0,0, 1,2, -1,2]], density:0})\r\n\tsim.addJoint({type:&quot;revolute&quot;, a:plank.body, b:fulcrum.body, collideConnected:false});\r\n\treturn weight;\r\n}\r\n\r\nsim.start();\r\n<\/pre>\n<p>Just playing around with QuickBox2D and brainstorming about a few features for the first non-alpha release. If you have any feature suggestions, please feel free to leave them in the comments of this post (see the end of this post for a list features to come in QuickBox2D 1.0).<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/swfs\/qb2d_gbsq.html\" \/><br \/>\nHave a look at the swf&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/qb2dgbs.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/qb2d_gbsq.swf&quot;,&quot;title&quot;:&quot;qb2d gbsq&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\">: qb2d gbsq<\/span><\/button><\/span><\/p>\n<p><strong>Upcoming Features for QuickBox2D<\/strong><br \/>\nSimplified collision detection &#8211; will hopefully be something like hitTest for QuickObject instances.<\/p>\n<p>QuickBox2D.totalTimeSteps &#8211; variable that keeps track of how many times b2World.Step() was called &#8211; useful for simple sequencing.<\/p>\n<p>QuickBox2D.addTimeStepEvent(callAt:Number, callback:Function) &#8211; calls a function when QuickBox2D.totalTimeSteps is equal to the callAt value.<\/p>\n<p>QuickBox2D.stepEvent &#8211; an event dispatched every time b2World.Step() is called.<\/p>\n<p><strong>New Renderer [probably not for 1.0 release]<\/strong><br \/>\nI&#8217;ve been toying with the idea of creating a new renderer for QuickBox2D. Currently all rigid bodies are DisplayObjects&#8230; this is great if you plan on skinning all your rigid bodies, but if you just have flat colors it is slower than debug draw &#8211; also, debug draw mode could be optimized a good deal. So I may create a simpler, faster renderer that draws to one Graphics instance (like debug draw mode) &#8211; but abides by QuickBox2D&#8217;s simple rendering params like lineColor, fillColor, lineAlpha etc&#8230;<\/p>\n<p>I also need to decide how to skin the rest of the joints, currently skins only work for distance joints&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; import Box2D.Common.Math.*; import Box2D.Collision.Shapes.*; &#x5B;SWF(width = 800, height = 600, backgroundColor = 0xFFFFFF, frameRate=60)] \/\/ hide everything for 300 ms visible = false; setTimeout(function():void{ visible = true}, 300); var sim:QuickBox2D = new QuickBox2D(this, {debug:false}); sim.setDefault({fillColor:0x666666, lineAlpha:0}) sim.createStageWalls(); makeLever(6 , 17.5, 9, &quot;right&quot;, 0.7); var circleA:QuickObject = sim.addCircle({x:2, y:3, radius:0.5, mass:4}); sim.addBox({x:15, y:12, width:2, [&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,14,15,4,16],"class_list":["post-401","post","type-post","status-publish","format-standard","hentry","category-box2d","category-motion","category-quickbox2d","tag-actionscript","tag-as3","tag-box2d","tag-flash","tag-quickbox2d"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/401","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=401"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/401\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}