demilion [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=35039 Joystick + Pico8 + HTML <p><em>using google translate</em></p> <img style="margin-bottom:16px" border=0 src="https://www.lexaloffle.com/bbs/files/35039/Screenshot_2019-02-24-10-51-30.png" alt="" /> <p>I received a lot of feedback from the previous project, regarding whether it is possible to add a joystick so I got down to work to see if we can do this and not die trying.</p> <p>What do we need:</p> <ul> <li>Read the awesome article by Eugene Andruszczenko(<a href="https://github.com/32teeth/html5-plugin-canvas-gamepad">https://github.com/32teeth/html5-plugin-canvas-gamepad</a>).</li> <li>Your PICO-8 html cartridge (html and js).</li> </ul> <p>Now a quick lesson of what we are doing:</p> <ul> <li>1) Adding the buttons (I add the info on .js of the game):</li> </ul> <p><code>YOUR_GAME.js</code></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>CanvasGamepad.setup({ start:false, buttons:[ {name:&quot;jump&quot;} ] });</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <ul> <li>2) Mapping our controller detection on the game.js (you can found the complete code at the end of this article).<br /> This is the line that make the magic:</li> </ul> <p><code>game.js</code></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>//buttons if(map[&quot;a&quot;] == 1){SimulateKey(90);} if(map[&quot;b&quot;] == 1){SimulateKey(88);} if(map[&quot;x&quot;] == 1){SimulateKey(88);} if(map[&quot;y&quot;] == 1){SimulateKey(90);} //joystick if(x == 0 &amp;&amp; y == 0){ SimulateKeyUp(37);SimulateKeyUp(38);SimulateKeyUp(39);SimulateKeyUp(40); } if(x == -1 &amp;&amp; y == 0){ SimulateKey(37);//btn-left SimulateKeyUp(38);SimulateKeyUp(39);SimulateKeyUp(40); } if(x == 1 &amp;&amp; y == 0){ SimulateKey(39);//btn-right SimulateKeyUp(37);SimulateKeyUp(38);SimulateKeyUp(40); } if(x == 0 &amp;&amp; y == -1){ SimulateKey(38);//btn-down SimulateKeyUp(37);SimulateKeyUp(40);SimulateKeyUp(39); } if(x == 0 &amp;&amp; y == 1){ SimulateKey(40);//btn-up SimulateKeyUp(37);SimulateKeyUp(39);SimulateKeyUp(38); } if(x == -1 &amp;&amp; y == 1){ SimulateKey(37);//btn-left SimulateKey(40);//btn-down SimulateKeyUp(38);SimulateKeyUp(39); } if(x == -1 &amp;&amp; y == -1){ SimulateKey(37);//btn-left SimulateKey(38);//btn-down SimulateKeyUp(39);SimulateKeyUp(40); } if(x == 1 &amp;&amp; y == 1){ SimulateKey(39);//btn-right SimulateKey(40);//btn-up SimulateKeyUp(37);SimulateKeyUp(38); } if(x == 1 &amp;&amp; y == -1){ SimulateKey(39);//btn-right SimulateKey(38);//btn-down SimulateKeyUp(37);SimulateKeyUp(40); }</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <ul> <li>3) calling some extra buttons (START button):</li> </ul> <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>if(map[&quot;start&quot;] == 1 &amp;&amp; banner == false) { banner = true; Module.pico8TogglePaused(); //I sent a signal to my &quot;Android&quot; app to show an ad. //Android.startRewardVideoAndroidFunction(&quot;&quot;); } </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>You.- Dude, i&acute;m really don't care about this chit chat.<br /> Me .- Ok, ok, I leave my code so you can steal it <a href="https://github.com/demilion/PICO-8-Joystick">https://github.com/demilion/PICO-8-Joystick</a><br /> (you only need to changes your YOUR_GAME.js and read step one on this article only to be sure you get it).</p> <p>| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|<br /> | [Buy me a coffee]() |<br /> | PLEASE!!!! |<br /> | _____ ___|<br /> (\__/) ||<br /> (&bull;ㅅ&bull;) ||<br /> /   づ [i need money]()<br /> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=6HMGKKPGQCLBN&amp;source=url">https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=6HMGKKPGQCLBN&amp;source=url</a> </p> <p>Let me know what you think!!!!!!<br /> <a href="https://www.amazon.com/Demilion-Classic/dp/B07S7SLDPZ/ref=sr_1_1?keywords=demilion&amp;qid=1560866513&amp;s=gateway&amp;sr=8-1">https://www.amazon.com/Demilion-Classic/dp/B07S7SLDPZ/ref=sr_1_1?keywords=demilion&amp;qid=1560866513&amp;s=gateway&amp;sr=8-1</a></p> https://www.lexaloffle.com/bbs/?tid=33389 https://www.lexaloffle.com/bbs/?tid=33389 Tue, 26 Feb 2019 02:00:28 UTC Android + Pico-8 <p><em>using google translate</em></p> <p><blockquote class="twitter-tweet" data-lang="en"><a href="https://twitter.com/lexaloffle/status/1081383766868746243">[tweet <img src="/gfx/load16.gif">]</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></p> <p>At the beginning of the year I started using PICO-8 when I found out that Celeste was born from such a simple concept.<br /> The first thing I could discover using PICO is that you can export to html...</p> <p>if you can use HTML you can visualize it directly on Android using a tool called WebView.</p> <p>This is a step-by-step tutorial to use your PICO-8 cartridges on your Android phone, let's begin shall we?</p> <p>What do we need:</p> <ul> <li>Android Studio(<a href="https://developer.android.com/studio/">https://developer.android.com/studio/</a>).</li> <li>Your PICO-8 html cartridge (html and js).</li> </ul> <p>Now we need to understand what we are going to do:</p> <p>1) create an application on Android (the classic helloworld: <a href="https://developer.android.com/training/basics/firstapp/">https://developer.android.com/training/basics/firstapp/</a>).<br /> 2) Add the WebView tool to your app (<a href="https://jgvcodigo.blogspot.com/2017/12/webview-android.html">https://jgvcodigo.blogspot.com/2017/12/webview-android.html</a>).<br /> 3) Add the controls on the html file of your cartridge.<br /> You can use the following template and call your .js file:</p> <p><a href="https://github.com/headjump/pico8_html_template">https://github.com/headjump/pico8_html_template</a> (awesome morningtoast post: <a href="https://www.lexaloffle.com/bbs/?tid=30147">https://www.lexaloffle.com/bbs/?tid=30147</a>)</p> <p>4)Finally add your html and js file inside your android project:<br /> <code>C: \ Users \ AndroidStudioProjects \ YOUR_PROYECT \ app \ src \ main \ assets</code></p> <p>This is the line that made the magic:<br /> <strong>myWebView.loadUrl(&quot;file:///android_asset/YOUR_GAME.html&quot;);</strong><br /> This line sends your html.</p> <p><code>MainActivity.java</code></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> package com..; import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.webkit.WebView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView myWebView = (WebView) this.findViewById(R.id.webView); myWebView.loadUrl(&quot;file:///android_asset/YOUR_GAME.html&quot;); } } </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <img style="margin-bottom:16px" border=0 src="https://www.lexaloffle.com/bbs/files/35039/pico_8_android.png" alt="" /> <p>So as you can see we are calling a simple html on android to be able to show our game. It seems the easiest way to have your first android application working.</p> <p>And you don&acute;t need as much knowledge to publish your Pico-8 game on Google play.</p> <p>I leave my code so you can steal it <a href="https://github.com/demilion/Celeste-Classic-PICO-8-Android">https://github.com/demilion/Celeste-Classic-PICO-8-Android</a></p> <p>It has a couple of extra lines such as having ads or integrated purchases.</p> <p>{\__/}<br /> ( &bull; . &bull;)<br /> /&gt;&hearts; u want this?...</p> <p>{\__/}<br /> ( &bull; . &bull;)<br /> &hearts;&lt; \ NoOoOoOoO</p> <p>{\__/}<br /> ( &bull; . &bull;)<br /> /&gt;&hearts; im joking but <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=6HMGKKPGQCLBN&amp;amp;source=url">Buy me a coffee</a></p> <p>Let me know what you think!!!!!!</p> <h2><a href="https://www.amazon.com/Demilion-Classic/dp/B07S7SLDPZ/ref=sr_1_1?keywords=demilion&amp;qid=1560866513&amp;s=gateway&amp;sr=8-1">https://www.amazon.com/Demilion-Classic/dp/B07S7SLDPZ/ref=sr_1_1?keywords=demilion&amp;qid=1560866513&amp;s=gateway&amp;sr=8-1</a></h2> https://www.lexaloffle.com/bbs/?tid=33270 https://www.lexaloffle.com/bbs/?tid=33270 Fri, 15 Feb 2019 03:15:12 UTC