dariusdan [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=17041 dariusdan's 8-dir movement <p> <table><tr><td> <a href="/bbs/?pid=77200#p"> <img src="/bbs/thumbs/pico8_dariusdans8dirmove-1.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=77200#p"> dariusdans8dirmove</a><br><br> by <a href="/bbs/?uid=17041"> dariusdan</a> <br><br><br> <a href="/bbs/?pid=77200#p"> [Click to Play]</a> </td></tr></table> </p> <p>This is my code snippet for 8-dir movement in PICO-8. There are some in BBS like this but I think I have something to add here because:</p> <p>1 - It doesn't move faster when going diagonals;<br /> 2 - It can move at speeds below 1 pixel/frame (sub-pixel movement);<br /> 3 - And most importantly: IT DOESN'T HAVE ANY ANNOYING JITTERING (the staircase effect)!!!</p> <p>Feel free to scrutinize my code and give me any constructive tips. I am still getting started with PICO-8 and Lua.</p> https://www.lexaloffle.com/bbs/?tid=38130 https://www.lexaloffle.com/bbs/?tid=38130 Tue, 26 May 2020 00:38:11 UTC Frame rate duration constancy <p>Do anyone know how constant is the duration of a frame in PICO-8?</p> <p>I am considering making samething that will use rhythm and decided to use the frames as a time basis. First thing I implemented was a simple metronome.</p> <p>Code below:</p> <p>This function rounds a number n to the nearest integer that is multiple of m:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function round_mult(n, m) -- n is the number to be -- rounded. -- m is the integer -- significance. -- returns the nearest -- multiple of m. if (n % m) == 0 then return n else v_up = flr(n) + 1 v_up = n + (m - n % m) v_dn = flr(n) v_dn = n - (n % m) if (v_up - n) &lt;= (n - v_dn) then return v_up else return v_dn end end end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>On the metronome itself, I want to put a bpm and use the nearest bpm that can fit inside a frame time.</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function _init() bpm = 50 -- this is not necessarily the actual bpm ingame. btime = 60/bpm -- time per beat in seconds subdivs = 4 -- subdivisions of a beat fps = stat(7) -- framerate ftime = 1/fps -- time per frame bframes = round_mult( btime / ftime, subdivs) -- the actual bpm to be used, but in frames instead of seconds curframe = 1 -- frame count starts at 1 end function _update() if curframe == bframes then sfx(1) -- this is the end of a beat curframe = 1 elseif (curframe % (bframes / subdivs)) == 0 then sfx(0) -- this is a subdivision of a beat curframe = curframe + 1 else curframe = curframe + 1 end end function _draw() cls() print(tostr(curframe)) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>The thing is, I recorded the beeps and I noticed (using audacity) that the times of the beats are not always the same. It differs a little bit. Can frames take slightly longer or shorter times to occur inside PICO-8?</p> https://www.lexaloffle.com/bbs/?tid=31006 https://www.lexaloffle.com/bbs/?tid=31006 Sun, 25 Mar 2018 21:25:37 UTC