{"id":418,"date":"2009-09-30T08:30:09","date_gmt":"2009-09-30T15:30:09","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2261"},"modified":"2009-09-30T08:30:09","modified_gmt":"2009-09-30T15:30:09","slug":"quickfrim","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=418","title":{"rendered":"QuickFRIM"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.animation.*;\r\n\r\nstage.frameRate = 60.0;\r\n\r\n\/\/ args: main display object, Hz\r\nvar frim:QuickFRIM = new QuickFRIM(this, 60.0);\r\n\r\n\/\/ start QuickFRIM internal loop\r\nfrim.start();\r\n\r\n\/\/ listen for step and render\r\nfrim.addEventListener(QuickFRIM.STEP, onStep);\r\nfrim.addEventListener(QuickFRIM.RENDER, onRender);\r\n\r\n\/\/ happes from 0 or more times per frame depending on your framerate and desired Hz\r\nfunction onStep(evt:Event):void {\r\n\t \/\/\r\n}\r\n\r\n\/\/ happens once per frame after all STEP events have\r\n\/\/ been dispatched\r\nfunction onRender(evt:Event):void{\r\n\t \/\/ number of times a step even was dispatched this frame\r\n\t trace(frim.stepsPerFrame);\r\n}\r\n<\/pre>\n<p>I have been using this QuickFRIM class for the past few days and have been pretty happy with it. Being someone who still occasionally likes to roll their own AS animation&#8230; with Zeno&#8217;s, Hooke&#8217;s, Polar Coordinates etc&#8230; Having a simple solution for frame-rate independent motion is nice&#8230; especially for small games&#8230; I used to have a more complex technique for this that was significantly harder to maintain. The above is just the basic setup for using the class.<\/p>\n<p>The most important part of the class is the Hz (Hertz) argument in the QuickFRIM constructor. This should be set to how many times you want your step event to be dispatched per second. Usually this would simply be set to your target fps&#8230; so if your swf fps is 30, you should probably pass 30 to the QuickFRIM constructor. If you were to have an fps of 30 and pass 60Hz to your constructor&#8230; the step event would consistently dispatch 2 times per frame. If you had an Hz of 10 and an fps of 30, your step even would only get triggered every three frames etc&#8230; <\/p>\n<p>Here&#8217;s a demo&#8230;<br \/>\n<a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/quick_frim.html\" target=\"blank\"><br \/>\n<img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/qfrim.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/quick_frim.swf&quot;,&quot;title&quot;:&quot;quick frim&quot;,&quot;width&quot;:800,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#000000&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: quick frim<\/span><\/button><\/span><\/p>\n<p>I should note that I spent some time looking at different FRIM implementations online and in the end I found this thread <a href=\"https:\/\/developer.playfirst.com\/node\/860\">https:\/\/developer.playfirst.com\/node\/860<\/a> which my implementation is significantly based upon. <\/p>\n<p><a href=\"https:\/\/actionsnippet.com\/source\/QuickFRIM.as\" target=\"blank\">Here&#8217;s the code for the class<\/a><br \/>\n<a href=\"https:\/\/actionsnippet.com\/source\/QuickFRIM.zip\" target=\"blank\">Here you can download a zip of the class<\/a><\/p>\n<p>&#8230; and here is some very quick documentation<br \/>\nQuickFRIM:<\/p>\n<p>\/*<br \/>\n@param main &#8211; the main timeline or other DisplayObject<br \/>\n@param hz &#8211; Hertz for he timeStep<br \/>\n*\/<br \/>\nnew QuickFRIM(main:DisplayObject, hz:Number = 60.0)<\/p>\n<p>\/\/ dispatched every time a step even occurs<br \/>\nQuickFRIM.STEP<\/p>\n<p>\/\/ dispatched after all step events have occurred at the end of the frame<br \/>\nQuickFRIM.RENDER<\/p>\n<p>\/\/ start dispatching events<br \/>\npublic function start();<\/p>\n<p>\/\/ stop dispatching events<br \/>\npublic function stop();<\/p>\n<p>\/\/ 1.0 \/ Hertz<br \/>\npublic var timeStep:Number;<\/p>\n<p>\/\/ total number of time steps that have been dispatched<br \/>\npublic var totalTimeSteps:Number=0;<\/p>\n<p>\/\/ numer of step events dispatched this frame<br \/>\npublic var stepsPerFrame:int=0;<\/p>\n<p>\/\/ boolean to disable FRIM<br \/>\npublic var disable:Boolean = false;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.animation.*; stage.frameRate = 60.0; \/\/ args: main display object, Hz var frim:QuickFRIM = new QuickFRIM(this, 60.0); \/\/ start QuickFRIM internal loop frim.start(); \/\/ listen for step and render frim.addEventListener(QuickFRIM.STEP, onStep); frim.addEventListener(QuickFRIM.RENDER, onRender); \/\/ happes from 0 or more times per frame depending on your framerate and desired Hz function onStep(evt:Event):void { \/\/ } \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[3,14,4],"class_list":["post-418","post","type-post","status-publish","format-standard","hentry","category-motion","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/418","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=418"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}