<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matt Buckley on Medium]]></title>
        <description><![CDATA[Stories by Matt Buckley on Medium]]></description>
        <link>https://medium.com/@mattThousand?source=rss-5abfd4ca6090------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6542OwHYzaIcI-lHAsVtpg.png</url>
            <title>Stories by Matt Buckley on Medium</title>
            <link>https://medium.com/@mattThousand?source=rss-5abfd4ca6090------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:00:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mattThousand/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Classic Onboarding UI for SwiftUI]]></title>
            <link>https://medium.com/nice-things-ios-android-development/before-swiftuicame-along-uipagecontrol-was-the-obvious-choice-for-putting-together-a-typical-59c10652901e?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/59c10652901e</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftlang]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Tue, 17 Mar 2020 21:10:41 GMT</pubDate>
            <atom:updated>2020-03-17T21:14:01.510Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*5By0jj7bMZG0FCkHslrw3g.gif" /></figure><p>Before SwiftUIcame along, UIPageControl was the obvious choice for putting together a typical paginated onboarding sequence. We can still integrate UIKitclasses into SwiftUIeasily enough, but having a first party implementation within the framework is preferable.</p><p>We sought to keep things as simple as possible with our implementation, but as you can see there’s still a fair amount of tricky state management to take care of.</p><p>At a high level, our PaginatedViewjust contains an HStack, which contains each constituent “page” of our page control. We attach a DragGestureto the PaginatedView, which it uses to set the appropriate index of the current page. Finally, the PaginatedViewpasses data down to a DotsComponent, which highlights the appropriate dot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7201bbdd2a79d01e34da66fcfeb4486/href">https://medium.com/media/b7201bbdd2a79d01e34da66fcfeb4486/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59c10652901e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/before-swiftuicame-along-uipagecontrol-was-the-obvious-choice-for-putting-together-a-typical-59c10652901e">Classic Onboarding UI for SwiftUI</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animating Shapes with SwiftUI]]></title>
            <link>https://medium.com/nice-things-ios-android-development/swiftuis-shapeprotocol-gives-us-a-simple-2d-shape-that-can-be-customized-and-animated-7b472c81d6e5?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b472c81d6e5</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Mon, 25 Nov 2019 16:02:17 GMT</pubDate>
            <atom:updated>2019-11-25T18:15:07.761Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? See what we’re doing at </em><a href="https://www.nicethings.io/"><strong><em>Nice Things</em></strong></a><strong><em> </em></strong><em>— we’re the creators of </em><a href="https://apps.apple.com/us/app/bentoblox-puzzle-game/id1361865513"><strong><em>BentoBlox</em></strong></a><strong><em>.</em></strong><em>We also build and maintain great mobile apps for clients large and small. We’d love to work with you on your next project.</em></p><p>SwiftUI’s Shapeprotocol gives us a simple 2D shape that can be customized and animated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*Av9v2a4cokYDoT8jULL1_Q.gif" /></figure><p>We can choose from Circle, Ellipse, Capsule, RoundedRectangle, among others. Calling .trim allows us to specify the “fraction” of the shape to draw. .stroke specifies that only the outline of the shape be drawn. We specify a frameto contain the shape, and an animation to control the look and feel of how the shape is drawn.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b81bdb526ba3ad6ea8f0872349fca522/href">https://medium.com/media/b81bdb526ba3ad6ea8f0872349fca522/href</a></iframe><p><em>Like this post? See what we’re doing at </em><a href="https://www.nicethings.io/"><strong><em>Nice Things</em></strong></a><strong><em> </em></strong><em>— we’re the creators of </em><a href="https://apps.apple.com/us/app/bentoblox-puzzle-game/id1361865513"><strong><em>BentoBlox</em></strong></a><strong><em>.</em></strong><em>We also build and maintain great mobile apps for clients large and small. We’d love to work with you on your next project.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b472c81d6e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/swiftuis-shapeprotocol-gives-us-a-simple-2d-shape-that-can-be-customized-and-animated-7b472c81d6e5">Animating Shapes with SwiftUI</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write Adobe XD Plugins Using TypeScript]]></title>
            <link>https://levelup.gitconnected.com/write-adobe-xd-plugins-using-typescript-40457b16cbc0?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/40457b16cbc0</guid>
            <category><![CDATA[adobe-xd]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 01:56:28 GMT</pubDate>
            <atom:updated>2018-12-12T02:34:17.753Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><p><a href="https://www.adobe.com/products/xd.html">Adobe XD</a> is a desktop application used by mobile/web designers to wireframe and prototype apps and websites (if you’re familiar with <a href="https://www.sketchapp.com/">Sketch</a>, it serves a similar use case).</p><p>As a developer, you can write 3rd party plugins for use inXD, but it comes with a caveat: you’ll be using JavaScript. If you’re anything like me, and you’ve enjoyed the niceties of a robust type system over the years, the prospect of writing software without one is a deal-breaker.</p><p>Thankfully, there’s TypeScript.</p><p>TypeScript is exactly what is sounds like: typed Javascript. It supports JavaScript’s standard types (string, number, etc), as well as any custom types you might decide to write.</p><p>TypeScript&#39;s extensibility — developers can <em>extend</em> the basic type system with types of their own — is crucial. With it, the type system can be extended to include types unique to the Adobe XD API ( Point, Matrix, Rectangle, etc).</p><p><a href="https://gitconnected.com/learn/typescript">Learn TypeScript - Best TypeScript Tutorials (2020) | gitconnected</a></p><p>In this post I’ll walk through the process of building a super-simple XD plugin using TypeScript.</p><blockquote><em>Before moving ahead, go through </em><a href="https://adobexdplatform.com/plugin-docs/tutorials/quick-start/"><em>Adobe’s Quick Start Tutorial</em></a><em> so that you have a working javascript project to start with. By the end, you should have a project that looks like </em><a href="https://gitlab.com/mattthousand/adobexdstarter"><em>this</em></a><em> (* also be sure to replace the </em><em>id value in </em><em>manifest.json with a unique plugin ID from the </em><em>Adobe I/O Console).</em></blockquote><p>After going through the Quick Start tutorial, you should have a project with 2 files in it: main.js andmanifest.json. In the same directory, create a main.ts file. This is where you will put your TypeScript code.</p><p>But before you start writing code, you’ll need Adobe XD&#39;s types to be defined so you can use them. Fortunately, <a href="https://github.com/pklaschka">Pablo</a> has written types for XD, and you can them pull down by creating apackage.json file in your root directory and adding his repo as a dependency:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*UArQ1Pqg0QzaKTibDG8lyA.png" /></figure><p>Just runnpm install from the command line to pull down the types.</p><p>Now you can start writing your plugin. Below is a simple TypeScript program that imports a couple of Adobe types and draws a purple ellipse:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*vIbBmxb-a5f6Ew7gWClDDQ.png" /></figure><p>Specifying types (const newElement: Ellipse = new Ellipse()) allows you to take full advantage of the compiler and uncover type-related errors at compile time. For instance, specifying const newElement: Ellipse = New Color()will cause your code not to compile — and save you the nightmare of discovering the error at run time.</p><p>The next thing you’ll need is a way for Adobe XD to access your code.</p><p>Go to the manifest.json file in your root directory. This file contains basic metadata about your plugin, including the names for any commands that should be exposed to the user in XD. Add your createEllipse command to the uiEntryPoints collection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*-G8irlThWG6Xv2NWOtoc3Q.png" /></figure><p>The final step you need to take before compiling your TypeScript program and running your plugin is to create a tsconfig.json file. This file specifies source code containing your type definitions and any compiler options you might choose:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8nKcMEggTVTVJhDmhZjsA.png" /></figure><p>At this point you can compile your TypeScript code. From the command line, navigate to your plugin’s root directory and invoke the compiler with tsc. Having done that, your main.js file now will contain javascript compiled from the code you wrote in main.ts.</p><p>And now you can finally run your plugin. Open Adobe XD, navigate to Plugins, and click Create Ellipse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uAH93M3tISbIdOBqipVg2w.gif" /></figure><p>Viola. That’s all folks. Check out the completed plugin <a href="https://gitlab.com/mattthousand/adobexdstarter">here</a>, and comment with any feedback you have on this little exploration into TypeScript for AdobeXD.</p><p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><figure><a href="https://levelup.gitconnected.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9uYu-fFL3hIQLGVu0o-EQ.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40457b16cbc0" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/write-adobe-xd-plugins-using-typescript-40457b16cbc0">Write Adobe XD Plugins Using TypeScript</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Profiling in Unity]]></title>
            <link>https://medium.com/nice-things-ios-android-development/profiling-in-unity-7e7fcedbeed4?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e7fcedbeed4</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity-5]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Sat, 01 Dec 2018 22:06:58 GMT</pubDate>
            <atom:updated>2018-12-02T14:51:58.823Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><p>This week I’m taking a break from active prototyping to learn about Unity’s built-in profiling capabilities.</p><p>The Unity profiler enables you to monitor CPU performance, rendering, memory allocation, physics, and more. Using the profiler, you can:</p><ul><li>Identify where and when FPS drops suddenly</li><li>Tell how much time your program takes to render an individual frame</li><li>Identify which function calls in your code are taking up the most CPU</li><li>Tell how much time those function calls take to execute</li><li>Isolate performance issues on individual devices/platforms (iPhone, Android, etc)</li></ul><p>With the profiler, you can zero-in on bottlenecks and get to work optimizing your code.</p><h3>The Basics</h3><p>You can find the profiler in Window -&gt; Analysis -&gt; Profiler or open it simply by hitting ⌘7. With the profiler open, click Play and you’ll see the profiler tab populate with data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e1hlWR_SEBMvCIMlbcf1NQ.png" /></figure><p>There are a number of important elements to make note of here, so I’ll go through each piece individually.</p><h4><strong>CPU Usage</strong></h4><p>Selecting CPU Usage in the top panel of the profiler tab surfaces data in the bottom panel. The line graph in the top panel visualizes CPU usage over time (by individual frame). Clicking on any point in this timeline isolates an individual frame and shows the function calls taking place during that frame in the bottom panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mBNebjUeajxQQrLnKE1EiQ.png" /></figure><p>The columns in the bottom panel to the right of each function call are self-explanatory, but it’s worth highlighting the two you’ll find especially useful:</p><ul><li>Total- shows the percentage of total CPU being utilized by a given function call</li><li>Time- shows the time (in milliseconds) taken to execute a given function call</li></ul><p>For even more detail, you can enableDeep Profile mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npOKPd-BfT_SRcnjCR3yxQ.png" /></figure><p>This ensures that <em>all</em> function calls are recorded individually. Deep Profile allows for, well, a “deeper”, level of insight into where time is being spent in your game code, but uses a great deal of memory and can cause gameplay to visibly slow down and should be enabled with that caveat in mind.</p><h4>Memory</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZ6c7p1fDwREfmiyx1LkNg.png" /></figure><p>The Memory tab shows, as you might expect, memory allocation during each frame. Irregularities here are a sign that you might have a memory leak, or otherwise be able to improve memory management and keep your app/game’s footprint small by making a code change.</p><p>Selecting the Simple view in the dropdown menu of the bottom panel surfaces a high-level overview of memory usage for a given frame. Toggling to Detailed allows you to inspect the memory footprint of individual objects and assets, which can prove very useful in identifying any large objects that might be loaded into memory unnecessarily for a given frame.</p><h4>Rendering</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2IF1UjaeOD6rRzyT72Biqg.png" /></figure><p>The rendering tab shows the number of batches, draw calls, triangles and vertices at a given frame. Clicking on a single frame surfaces more detailed information and statistics in the bottom panel.</p><h4>Physics and Physics2D</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yZAVX1D4ZoIajf9kiOCFPA.png" /></figure><p>The Physics and Physics2D tabs track the number of bodies (components) active during each frame. Comparing peaks and valleys here against any spikes you see in theCPU timeline view can help you identify physics-intensive operations that adversely impact performance.</p><h3>The Profiler Can Do Even More</h3><p>The profiler also includes tabs for audio, video, networking, and much more. I may check these out in a future post, but we’ve covered a few of the big-ticket items here already.</p><p>How do you use the Unity Profiler? Are there tools/capabilities that you find particularly useful? I’d love to hear about your experience profiling apps and games in Unity in the comments below.</p><p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e7fcedbeed4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/profiling-in-unity-7e7fcedbeed4">Profiling in Unity</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Procedural Level Generation In Unity]]></title>
            <link>https://medium.com/nice-things-ios-android-development/simple-procedural-level-generation-in-unity-b8289e3486ec?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8289e3486ec</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 02:28:27 GMT</pubDate>
            <atom:updated>2018-11-26T02:44:32.695Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><p>This week I’m continuing to prototype the 2D vertical platformer I began working on earlier in the month.</p><p>The game mechanic is a classic, uncomplicated one (go play the originalNES <a href="https://en.wikipedia.org/wiki/Ice_Climber"><em>Ice Climber</em></a> title — that’s essentially what I’m aiming to recreate). The player makes “progress” by moving upward through space, jumping from one platform to another.</p><p>One way to approach level generation for this game is to write a script that generates all platforms at once. But doing so limits the scope of the game. I opted instead for a simple procedural implementation that generates platforms as needed during gameplay as the player moves upward through space.</p><p>The approach is simple and consists of 3 components:</p><ol><li>A Platform Spawner game object</li><li>A Platform Collector game object</li><li>A Platformprefab</li></ol><p>The idea is that both the Platform Spawner and Platform Collector move with the main camera, the Platform Collector telling the Platform Spawner to generate a new platform each time it comes into contact with an existingPlatform as it moves upward following the player’s progress.</p><p>To accomplish this, I add both as child objects of the Main Camera. The Platform Spawner is positioned above the main camera’s viewport, while the Platform Collector is positioned below. To ensure that the Platform Collector collides with Platforms positioned at random horizontal positions, I add aBoxCollider2D component and extend it horizontally in both directions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ApcwFTIcJkQ3pnFSr6hd3A.png" /></figure><p>The Platform prefab is simple: just a GameObject with BoxCollider2D and Sprite Renderer components attached:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xpXUYtRM5HPzO-TpA1q6Sg.png" /></figure><p>I also create and add a “Platform” tag to the Platform prefab, which will come into play shortly.</p><p>The Platform Spawner&#39;s role is to generate an initial set of platforms, and then generate an additional platform whenever the Platform Collector comes into contact with a Platform as the camera follows the player’s progress and moves upward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*ZgkfBW2Qw6Xd7JJlEV9Msw.gif" /></figure><p>The logic for this lives in a few small scripts (find them <a href="https://gitlab.com/snippets/1783772">here</a>, <a href="https://gitlab.com/snippets/1783773">here</a>, and <a href="https://gitlab.com/snippets/1783777">here</a>) attached to the Platform Spawner and Platform Collector game objects respectively.</p><p>The Platform Collector script consists of a simple check in the OnTriggerEnter2D method. If the collider it comes into contact with is tagged as a Platform, it calls a method on the Platform Spawner to position a new Platform.</p><pre>void OnTriggerEnter2D(Collider2D other)<br>{<br>    if (other.tag == Constants.platformTag)<br>    {<br>        PlatformSpawner.Instance.PositionNewPlatform();<br>    }<br>}</pre><p>This week, time permitting, I’ll be adding a few things to round out the basic gameplay (obstacles, a “boss”, we’ll see). In the meantime I’d love any feedback, suggestions, or thoughts you might have about this post.</p><p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8289e3486ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/simple-procedural-level-generation-in-unity-b8289e3486ec">Simple Procedural Level Generation In Unity</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity: Handling Input from Multiple Sources (controllers, keyboards, etc)]]></title>
            <link>https://medium.com/nice-things-ios-android-development/unity-handling-input-from-multiple-sources-controllers-keyboards-etc-951a263fa098?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/951a263fa098</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[mobile-game-development]]></category>
            <category><![CDATA[indie-game]]></category>
            <category><![CDATA[indiedev]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Mon, 19 Nov 2018 01:54:19 GMT</pubDate>
            <atom:updated>2018-11-26T02:42:16.526Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><p>This week I’m prototyping a game intended to run on multiple platforms. One of the core challenges is anticipating and handling for user input coming from a range of different sources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*45f3VRkBeKxT6O66fl7YMw.gif" /></figure><p>My initial approach relies on an Observer-Subscriber model: a singleton UserInputDeviceManager stores a reference to the currently connected input device (a controller, a keyboard, etc), and polls the buttons of that device on Update to determine if any button is in the pressed state:</p><pre>public class UserInputDeviceManager : Singleton&lt;UserInputDeviceManager&gt;<br>    {</pre><pre>    public UserInputDevice currentUserInputDevice;</pre><pre>    public UserInputDevice[] supportedUserInputDevices = new UserInputDevice[] {<br>            new XBoxOneController(),<br>            new PS3Controller(),<br>            new DualShock4Controller(),<br>            new KeyboardController()<br>    };</pre><pre>    override protected void Awake()<br>        {</pre><pre>            base.Awake();<br>            SetupCurrentUserInputDevice();<br>        }</pre><pre>    private void SetupCurrentUserInputDevice()<br>        {<br>            currentUserInputDevice = System.Array.Find(supportedUserInputDevices, m =&gt; m.IsConnected());<br>        }</pre><pre>    void Update()<br>        {<br>            currentUserInputDevice.PollButtons();<br>        }</pre><pre>    }</pre><pre>}</pre><p>In PollButtons, each UserInputDevice broadcasts an event for any button in the pressed state:</p><pre>    public void PollButtons()<br>        {<br>            ArrayList buttons = new ArrayList();<br>            buttons.Add(JumpButton);<br>            buttons.Add(ConfirmButton);<br>            buttons.Add(PauseButton);<br>            buttons.Add(DPad.LeftButton);<br>            buttons.Add(DPad.RightButton);<br>            buttons.Add(DPad.TopButton);<br>            buttons.Add(DPad.BottomButton);<br>            foreach (Button button in buttons)<br>            {<br>                if (button.CurrentState == Button.State.Pressed)<br>                {<br>                    OnButtonPress(button);<br>                }<br>            }<br>        }</pre><p>Subscribers can listen for this event, and execute logic accordingly. For example, I have a PlayerMovementController which moves my Player game object based on incoming events from the currently connected device:</p><pre>    public void HandleButtonPress(Button button)<br>    {<br>        switch (button.action)<br>        {<br>            case UserInputDevice.ButtonName.DPadLeft:<br>                MoveLeft();<br>                break;<br>            case UserInputDevice.ButtonName.DPadRight:<br>                MoveRight();<br>                break;<br>            case UserInputDevice.ButtonName.DPadUp:<br>                Jump();<br>                break;<br>            default:<br>                break;<br>        }<br>    }</pre><p>This approach is rather homespun; it makes sense and feels good at the moment, but I’m curious to see if it has staying power in this project.</p><p>How do you handle user input in your projects? I’d love to hear about alternative approaches from anyone willing to share their thoughts.</p><p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=951a263fa098" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/unity-handling-input-from-multiple-sources-controllers-keyboards-etc-951a263fa098">Unity: Handling Input from Multiple Sources (controllers, keyboards, etc)</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Good Patterns for Game Development]]></title>
            <link>https://medium.com/nice-things-ios-android-development/finding-good-patterns-for-game-development-dd7e01945cd7?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd7e01945cd7</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Thu, 08 Nov 2018 03:17:54 GMT</pubDate>
            <atom:updated>2018-11-18T16:59:55.566Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><p>The <em>Observer Pattern</em> has driven a lot of my thinking as a mobile app developer on a few recent projects.</p><p>The pattern lends itself well to the task of reducing state and managing data flow.</p><p>Game development poses a whole set of challenges that don’t appear in ordinary e-commerce iOS or Android apps, but the observer pattern comes in handy for things like scene management when you’re developing games in Unity.</p><h4>The Pattern</h4><p>On an abstract level the pattern consists of <em>subjects</em> which maintain a lists of <em>observers</em> which they notify automatically of any state changes.</p><p>In my implementation, an <em>observer</em> can be any method:</p><pre>private void DoSomething() {<br>    // Do Something...<br>}</pre><p>And a <em>subject</em> can be any Action:</p><pre>public event Action AfterSceneLoad;</pre><p>Adding an <em>observer</em> to a <em>subject</em> is as simple as:</p><pre>AfterSceneLoad += DoSomething;</pre><p>In the context of a Unity project, this can be tremendously useful for, say, hooking into specific points in the scene lifecycle. For example, <em>subjects</em> can notify <em>observers</em> after a scene loads and before it unloads.</p><pre>public class SceneController : MonoBehavior<br>{<br>    public event Action BeforeSceneUnload;<br>    public event Action AfterSceneLoad;<br>}</pre><p>ThisSceneController handles transitioning between individual scenes. <em>Observers</em> are notified every time a scene loads, and again just before a scene unloads.</p><p>To provide some consistent structure for classes that hold references to <em>observers</em>, I also create a simple interface for them implement:</p><pre>public interface IObserver<br>{<br>    void SetupObservers();<br>    void DismantleObservers();<br>}</pre><p>I add <em>observers</em> to relevant subjects in SetupObservers. To avoid memory leaks, I remove the same <em>observers</em> in DismantleObservers, which I make sure is called before any scene unloads:</p><pre>public class MainMenuController : MonoBehavior, IObserver, <br>{<br>    override void Awake()<br>    {<br>        SetupObservers();<br>        SceneController.Instance.BeforeSceneUnload += DismantleObservers;<br>    }</pre><pre>    public void SetupObservers()<br>    {<br>         SceneController.Instance.AfterSceneLoad += DoSomething;<br>    }</pre><pre>    private void DoSomething() {<br>        // Do Something...<br>    }</pre><pre>    public void DismantleObservers()<br>    {<br>         SceneController.Instance.BeforeSceneUnload += DoSomething;<br>    }</pre><pre>}</pre><h4>The Takeaway</h4><p>This pattern is especially useful in the context of a game, where interaction is driven from within the game (game objects interacting with each other, AI/enemies executing their own logic, etc) and from user input. Ultimately I’d like to add some structure to my usage of the pattern so that it can scale and continue to be maintainable in a larger project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd7e01945cd7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/finding-good-patterns-for-game-development-dd7e01945cd7">Finding Good Patterns for Game Development</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Depth in a 2D World]]></title>
            <link>https://medium.com/nice-things-ios-android-development/creating-depth-in-a-2d-world-a9971da8d349?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9971da8d349</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[indie-game]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[videogames]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Tue, 21 Aug 2018 13:55:23 GMT</pubDate>
            <atom:updated>2018-11-26T02:42:43.225Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><p>Top-down 2D games share a recognizable approach to perspective. But playing with depth and shadow can give your top-down game a distinct visual style.</p><p>Adding a little depth to your 2D worth is easier than you think. In fact, it can be accomplished with a little bit of scripting using ordinary sprites. Here’s how:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*2xKD89ozYEwozTXuzO0v0Q.gif" /></figure><p>First, import your sprite into Unity and drag it onto your scene.</p><p>Then create a new script, let’s call it SpriteShadow. This script will manage two SpriteRenderers (one for your sprite and another for its shadow). In SpriteShadow, create a few properties:</p><pre>// the (x, y) offset of the shadow from the &quot;subject&quot; sprite<br>private Vector2 shadowOffset = new Vector2(-.1f, -.1f);</pre><pre>// the SpriteRenderer for the &quot;shadow&quot; sprite<br>private SpriteRenderer shadowSpriteRenderer; </pre><pre>// the SpriteRenderer for the sprite casting the shadow<br>private SpriteRenderer subjectSpriteRenderer;</pre><p>Add additional properties to store the transform of your subject sprite and shadow sprite:</p><pre>// shadow sprite transform<br>private Transform shadowTransform;</pre><pre>// subject sprite transform<br>private Transform subjectSpriteTransform;</pre><p>In Start(), set subjectSpriteTransform to your gameObject&#39;s transform, and add shadowSpriteTransform as a child:</p><pre>void Start()<br> {<br>subjectSpriteTransform = transform;<br>  shadowTransform = new GameObject().transform;  <br>  shadowTransform.parent = subjectSpriteTransform;<br> }</pre><p>Also in Start(), set the subjectSpriteRenderer and shadowSpriteRenderer (create your shadowSpriteRenderer programmatically):</p><pre>void Start()<br> {</pre><pre>subjectSpriteTransform = transform;<br>  shadowTransform = new GameObject().transform;  <br>  shadowTransform.parent = subjectSpriteTransform;</pre><pre>    subjectSpriteRenderer = GetComponent&lt;SpriteRenderer&gt;();<br>  shadowSpriteRenderer =     shadowTransform.gameObject.AddComponent&lt;SpriteRenderer&gt;();<br> }</pre><p>You’ll also want your shadow to display <em>behind</em> your subject. This is easy to accomplish in your script. This can be accomplished by decrementing its sorting order by 1. Just add:</p><pre>shadowSpriteRenderer.sortingOrder =    subjectSpriteRenderer.sortingOrder - 1;</pre><p>to your Start() method.</p><p>Now, if your sprite moves or animates during gameplay, you’ll want your sprite’s shadow to follow along. To make sure this happens, update your shadow’s sprite’s transform in LateUpdate(). Also in LateUpdate(), set your shadowSpriteRenderer&#39;s sprite to match your subjectSpriteRenderer&#39;s sprite. This ensures that your shadow will retain the shape of its subject:</p><pre>void LateUpdate()<br> {<br>    shadowTransform.position = new Vector2(subjectSpriteTransform.position.x + shadowOffset.x,    subjectSpriteTransform.position.y + shadowOffset.y);  <br>    shadowSpriteRenderer.sprite = subjectSpriteRenderer.sprite;<br> }</pre><p>The final thing you’ll want to do is add a material to your shadow sprite in order to make it black (or dark grey, whatever your shadow color of choice might be).</p><p>To accomplish this, add a property for such a Material, and make it visible to in the Unity editor:</p><pre>[SerializeField]<br> private Material shadowMaterial;</pre><p>Create a new Material in Unity, add a Shader to it to give it a solid black color, and drag your Material onto your sprite (shaders are beyond the scope of this post, click <a href="https://docs.unity3d.com/Manual/Shaders.html">here</a> for more information).</p><p>Press Play, and you’ll see an elegant, pixel-art-esque shadow below your sprite .</p><p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9971da8d349" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/creating-depth-in-a-2d-world-a9971da8d349">Creating Depth in a 2D World</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic 2D “Screen Shake” in Unity]]></title>
            <link>https://medium.com/nice-things-ios-android-development/basic-2d-screen-shake-in-unity-9c27b56b516?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c27b56b516</guid>
            <category><![CDATA[indie-game]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[retrogames]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[gamedev]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Wed, 15 Aug 2018 00:47:48 GMT</pubDate>
            <atom:updated>2018-11-26T18:24:53.918Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><p>In 2D gaming, a screen shake effect tied to movements on screen can give important sensory feedback to the player.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*pKBbFAUzYsbmW2L3Tag-xA.gif" /></figure><p>In Unity, it’s simple to implement. Here’s one way to do it (<em>in the meantime if you want to look through the finished script, you can find it </em><a href="https://gitlab.com/snippets/1784442"><em>here</em></a>):</p><p>Create a new script (Create &gt; C# Script).</p><p>Call itShakeBehavior and attach it to your scene’s camera GameObject.</p><p>In ShakeBehavior, add a few variables:</p><pre> // Transform of the GameObject you want to shake<br> private Transform transform;<br> <br> // Desired duration of the shake effect<br> private float shakeDuration = 0f;<br> <br> // A measure of magnitude for the shake. Tweak based on your preference<br> private float shakeMagnitude = 0.7f;<br> <br> // A measure of how quickly the shake effect should evaporate<br> private float dampingSpeed = 1.0f;<br> <br> // The initial position of the GameObject<br> Vector3 initialPosition;</pre><p>Now, in Awake, store your camera’s transform:</p><pre>void Awake()<br>{<br>  if (transform == null)<br>  {<br>   transform = GetComponent(typeof(Transform)) as Transform;<br>  }<br>}</pre><p>Next, in OnEnable, store the initial position of your camera’sGameObject:</p><pre>void OnEnable()<br> {<br>  initialPosition = transform.localPosition;<br> }</pre><p>Put the logic for the “shake” effect in Update or FixedUpdate, either is fine.</p><p>The logic is simple. If shakeDuration is positive, adjust the game object’s transform by a random factor (that’s our shake). Decrement shakeDuration so that your camera doesn’t shake forever. Once shakeDuration reaches 0, return your camera’s GameObjectto its initial position:</p><pre>void Update()<br>{<br>  if (shakeDuration &gt; 0)<br>  {<br>   transform.localPosition = initialPosition + Random.insideUnitSphere * shakeMagnitude;<br>   <br>   shakeDuration -= Time.deltaTime * dampingSpeed;<br>  }<br>  else<br>  {<br>   shakeDuration = 0f;<br>   transform.localPosition = initialPosition;<br>  }<br>}</pre><p>It’s that easy. One final thing you can do is expose a function to the editor that allows you to wire up an event (such as an avatar bumping into a wall or hitting the ground after a glorious jump), to your shake effect:</p><pre>public void TriggerShake() {<br>  shakeDuration = 2.0f;<br>}</pre><p>With that in place, shaking the camera is as simple as adding a reference to a GameObject containing ShakeBehavior and calling TriggerShake() on it.</p><p><em>Like this post? You might like </em><a href="http://www.bentoblox.com/"><strong><em>BentoBlox</em></strong></a><strong><em> </em></strong><em>too — check out the game here on the </em><a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong><em>App Store</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c27b56b516" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/basic-2d-screen-shake-in-unity-9c27b56b516">Basic 2D “Screen Shake” in Unity</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Game Design: Level Generation Using Binary Space Partitioning]]></title>
            <link>https://medium.com/nice-things-ios-android-development/game-design-level-generation-using-binary-space-partitioning-e229230ab8b5?source=rss-5abfd4ca6090------2</link>
            <guid isPermaLink="false">https://medium.com/p/e229230ab8b5</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[indie-game]]></category>
            <category><![CDATA[mobile-games]]></category>
            <category><![CDATA[videogames]]></category>
            <category><![CDATA[gamedev]]></category>
            <dc:creator><![CDATA[Matt Buckley]]></dc:creator>
            <pubDate>Sat, 04 Aug 2018 20:48:13 GMT</pubDate>
            <atom:updated>2018-12-14T16:52:12.011Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Binary Space Partitioning</em> is a simple technique used to create 2D maps for puzzle games and platformers. We use BSP to generate “solvable” levels in <a href="http://www.bentoblox.com/"><strong>BentoBlox</strong></a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omepNkod9DRUHvKZBG1z9Q.png" /></figure><p>How exactly do we use BSP? In <a href="http://www.bentoblox.com/"><strong>BentoBlox</strong></a>, we recursively divide a grid into sub-grids no smaller than a minimum size. That’s the essence of BSP in this context. Abstractly, we’re just taking a rectangle and bisecting repeatedly until we have a grid of smaller rectangles:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*hW4X70fTO09JysRId4hLWw.gif" /></figure><p>Here’s how we do it:</p><p>We start with a Grid struct (<em>note: all code is Swift</em>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*V85cNQZs-ynJse84zXvm3w.png" /></figure><p>Next we extend our Grid with a function that divides it (horizontally or vertically) into 2 sub-grids:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*uGnV205RvQ7Rqt1iHIVcmQ.png" /></figure><p>With our Grid extended in this way, we can call our function recursively to generate a collection of sub-grids that fit inside our initial grid and don’t overlap.</p><p>But there’s something we need to watch out for. What’s to prevent us from generating sub-grids that are too small? A sub-grid of area 0 wouldn’t be very useful. To avoid this outcome we can tell our calling function to return once it generates a sub-grid below certain minimum size:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZFjO8R_qaWcuT8loDx4yA.png" /></figure><p>And that’s really all we need. Now we can generate a “solvable” level with a single function call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*y5-xpQZfJZsycTSKWghD4g.png" /></figure><pre>Which yields a level containing 4 rectangles of varying sizes:</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*vuvwYtRI-c47cAfez3_bRA.png" /></figure><p>You’ll discover more neat things like this in <a href="http://www.bentoblox.com/"><strong>BentoBlox</strong></a> — check out the game here on the <a href="https://itunes.apple.com/us/app/bentoblox/id1361865513?ls=1&amp;mt=8"><strong>App Store</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e229230ab8b5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nice-things-ios-android-development/game-design-level-generation-using-binary-space-partitioning-e229230ab8b5">Game Design: Level Generation Using Binary Space Partitioning</a> was originally published in <a href="https://medium.com/nice-things-ios-android-development">Nice Things | iOS + Android Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>