A common requirement for 2D games is to have some sort of fullscreen background, be it a color, sprite, particle system, or anything else, to provide mood and aesthetic to the contents of your game. While a static color can be used to great effect, this post will go over the technique that I use for fullscreen background images in Unity using a standard SpriteRenderer and just a little touch of code to retain the original image's aspect ratio.
Frequently in Unity you'll see OnMouseDown used to detect clicks on GameObjects. This works fine but it requires a script on the GameObject itself, and may require synchronization within the game when there are many clickable objects.
Recently I added categories to all the posts on this blog so that I could link to a page containing posts for a single category. For instance, a post could be categorized as Android or Unity3D, and visitors could see all posts related to that particular category. Additionally, it allows me to add Related Posts links to each post as you can see on the right.
While developing Byter for GitHub Game Off 2016, I wanted to allow players to pan and zoom the camera on both touch (tap and drag to pan, pinch to zoom) devices including Android and iOS, as well as using the mouse (click and drag to pan, mouse-wheel scroll to zoom) on the desktop and WebGL versions of the game. The camera for Byter has a fixed angle, meaning players cannot rotate it, but zooming and panning are important for collecting the *Lost Packets* in the game, and are a nice addition to allow interaction in a mostly static clicker style game.
GitHub's Game Off 2016 continues and it's now day 23 of the *Game Off*, and if you've been following along with my progress you'll know that a few days ago I published the first playable build of **Byter** at kylewbanks.com/byter! From here on out it's all tweaking, tuning, and polishing.
It's Day 19 of GitHub's Game Off 2016 and it's time for the final stretch! I've actually published the first playable version of the game, available in the browser using WebGL, so please head over to kylewbanks.com/byter and try it out!
It's just over the halfway point of GitHub's Game Off 2016, and I'm just an hour or so away from being *gameplay complete*, meaning there will only be polish and tuning remaining. I haven't made quite as much progress in the last few days as I had hoped (originally I had planned to be gameplay complete by now), however I'm still happy to be on track to complete the game jam in time.
Progress on my GitHub Game Off 2016 game continues, and with the halfway point of the competition approaching I've gotten to the point where the core gameplay is complete. Here's a look at some of the progress I've made over the last few days!
I haven’t spent a whole lot of time with React Native, mostly using it for prototyping or for quick tools I personally need. One common thing I seem to require though is a Modal component, and I was always thinking how strange it is that the Modal requires an onRequestClose callback on Android devices. It’s not strange to have required properties by any means, but the fact that this one property is Android only is...
As mentioned in my previous posts, I've been developing a clicker game for GitHub's Game Off 2016. Today marks Day 9 of the Game Off, and I've managed to make quite a bit of progress.
At this point I've got the camera controls and core UI elements complete, as well as a JSON formatted game configuration file where I've defined some of the devices, storage units, and upgrades you'll be able to collect throughout the game. I've also got the bits spawning and moving along a path to the storage unit when you click or hold the main clicker button.
Yesterday the theme of GitHub's Game Off 2016 was announced, and the ideas is to build a game over the course of a month related to hacking, modding and/or augmenting. The announcement states that your game must be *loosely* based on one or more of these themes, but I've decided to go head first into the hacking theme. Considering how busy this month is for me (I would have loved for this to be a month or two ago) I'm going to have to keep it simple and try to get a playable prototype as quickly as possible before using any spare time to polish and improve the game.
The Android [Canvas](https://developer.android.com/reference/android/graphics/Canvas.html) provides convenient methods for drawing simple shapes such as circles and rectangles, using [drawCircle](https://developer.android.com/reference/android/graphics/Canvas.html#drawCircle(float, float, float, android.graphics.Paint)) and [drawRect](https://developer.android.com/reference/android/graphics/Canvas.html#drawRect(android.graphics.Rect, android.graphics.Paint)) respectively, but beyond these the majority of shapes require some custom Path logic to draw. Two shapes that I was required to draw were triangles and rhombuses, so I thought I'd share how I accomplished this.
Android Intents allow developers to share data such as text, images and URLs with other apps. This is handy for Share buttons, allowing users to tweet, post, email or message their friends from within your app or game.
In today's post, I'd like to share with you how I conditionally render components in React Native. Let's say you want to show a Log In button for unauthenticated users, and a Log Out button for user's who have authenticated. How would you go about doing this?
Recently while writing test cases for s3fs I came upon a situation where a function returns an interface, however the underlying type of the interface is dependant on the input. What I wanted to do was validate that the appropriate type was being returned for each supported input scenario.
Since I personally dislike having unnecessary extras in my URLs, I always avoid file extensions like .html on my sites. This poses a problem with S3, because the built-in request rewrite tools are cumbersome and not overly flexible.
Particle systems are fantastic for all kinds of effects in games, including fire, explosions, smoke, water, lighting, galaxy simulations, and much more. Unity comes with a built-in ParticleSystem library that can be used to implement these effects in your 2D or 3D Unity game.
Converting the results of a SQL query to a struct in go is trivial, but sometimes you don't know ahead of time exactly what columns and types you're going to be retrieving, and a map is better suited for storing the results.
Maintaining locks across a cluster of application instances, be it multiple threads on the same server, or different servers altogether, is an often underestimated piece of developing clustered applications. It's relatively straightforward but there are some gotchas to look out for when implementing your distributed locking mechanisms.
Regardless of skill level, whether you're a beginner programmer or a seasoned engineer of twenty plus years, blogging will have benefits to you and your career. Aside from the usual idea of (potentially) earning some extra income, there are a number of benefits to blogging that may not be immediately obvious to folks who aren't actively writing about their work.
The more data you can collect about your content, the better suited you'll be to improve your content and grow your audience. Personally, I was curious what impact the length of my blog posts was having on the number of page views they received, so I set about tracking the word count of my posts in Google Analytics.
Whenever I push CSS or layout changes to the blog, I like to invalidate my CloudFront cache to ensure the changes propagate near-synchronously. For instance during a new UI update, if a CSS file were to take 12 hours to propagate into the caches, but the layout changes only take 4 hours, there would be 8 hours where the new layout isn't properly styled.
When discussing performance optimization of Unity games, be it 2D or 3D, object pooling is a commonly referred to technique to gain significant improvements. An object pool is essentially a set of pre-instantiated objects that can be recycled when they are no longer in use, and eventually reused as required.
Unimation is an open source project I've been developing that aims to make animations in Unity 2D and 3D projects simpler.
Having the Camera follow the player character is a common requirement for many types of games, so I thought I'd share a helpful trick to ensure the camera follows the player smoothly and fluidly.
Programming boils down to solving problems using computers, by writing code to accomplish tasks. It's not typically seen as the most physical activity, or anything related to a sport for that matter, so how can these two completely different acts have any correlation? It turns out, they actually translate and even benefit each other much more than you probably think.
Unity with Git and GitHub seems to be a little mysterious to some game developers, so I thought I'd share a video demonstrating how to use Unity with Git and GitHub.
A game that takes place in space may want to disable gravity for instance, while a platforming game may want to inverse gravity for a particular level or even on-the-fly with a power-up to walk on the ceiling. However you need gravity to behave in your 2D or 3D game, its as easy as a single line of code to make it happen.
Recently I came across a situation where I wanted to animate the background color of the app's Toolbar, TabLayout, FloatingActionButton, and the window StatusBar when the selected tab changes. To do this, I chose to use the ValueAnimator which allows you to iterate over the difference of two values over a timed interval. I also used an ArgbEvaluator for the ValueAnimator's evaluator to handle the calculation of each animation step between the two ARGB colors.
Allowing users to share screenshots of a their progress in a game, or their view of an app, is a great way to drive installs and increase the reach of your Android application. Users can certainly use the native screenshot functionality of their device, but it would be great to be able to provide a button or any other means of sharing their view from within the app, that takes a screenshot of the relevant content for them.
In this post I'll be going over how to create a fullscreen background image for your views in React Native. While I'll be focusing on fullscreen images in particular, this will actually directly apply to any background image, fullscreen or not.
It's a pretty common requirement in game development to need to know if a particular character or object is on the ground. For instance, your player may only be able to jump, attack, or interact while they are on the ground. A common way to check this is to use a Raycast, which essentially allows you to detect the distance between to physics bodies.
The following trick actually works for any Java interface, Android or otherwise, but I find this to be particularly painful in animation-heavy Android applications, so I'm going to be using the AnimationListener interface as an example.
Defer is a powerful control flow mechanism that is unique to Go (at least until Swift 2.0 added it). It allows you to defer a function call to the end of the currently executing function no matter how or where it returns. This is useful for many reasons, the most common of which are to close an open connection or unlock a Mutex immediately before the function ends.
Alpine Linux is a popular Linux distribution that is incredibly light-weight: approximately 5MB only. Deploying with Alpine is beneficial because downloading the Docker image is extremely fast, and you have no extra overhead from running services in your container that you don't need. Luckily the official golang Docker image has an Alpine variant that we can use, so adapting Alpine for our needs is going to be straightforward.
With AWS Auto Scaling Groups, you have a lot of options regarding how you scale, determining instance health, and where and how you launch your EC2 instances. One piece of the auto scaling configuration that I find myself frequently modifying from the default is the Health Check Type.
The Mutex (mutual exclusion lock) is an invaluable resource when synchronizing state across multiple goroutines, but I find that it's usage is somewhat mystifying to new Go developers. The truth is that mutexes are incredibly simple to use, but do come with a couple caveats that can have a serious impact on your software - namely deadlocks.
A while back I wrote about how to Use GSON to Fetch and Parse JSON into Java Models for Android, and that post proved to be quite popular even to this day. However I'd like to provide you with a new tutorial that goes over how to perform the same task of fetching and parsing JSON into Java objects with GSON, but using updated libraries such as Volley, and demonstrate how much cleaner and more maintainable the code becomes.
In Part 2 we created the layout and style of the calculator, but it still doesn't do anything. In Part 3, we'll continue from where we left off by handling touch events, performing the arithmetic, and updating the calculator UI using State.
In Part 1 we went through the setup of a 'Hello, React!' application. In Part 2, we'll continue from where we left off and begin laying out and styling our calculator app.
Animations, when used correctly, can be a simple way to enhance the user experience of your products, adding a little bit of fun that a motionless view just doesn't have. Today I'll be demonstrating how to add some basic left and right sliding animations to your Views and Activities on Android.
Square photos are all the rage now since Instagram introduced them back in 2010, but implementing them on Android is much more painful than you'd imagine.
Recently I wanted to add an animation to an ImageView to infinitely rotate in place, in order to create a custom loading spinner. The requirements were simple enough that customizing the ProgressBar view wasn't necessary, and we didn't need anything fancy like a GIF.
So you've written a Go application and you're ready to distribute it to your users, but how do you support platforms other than the one you develop on? Sure you could go out and buy a machine or lease a server of the target type, compile your application on there, and take the binary - but who wants to do all that? Not only is that costly, inefficient, tough to automate, but it's just an overall nightmare. Well luckily the solution is no-where near as complicated as that, as Go comes with cross-compilation support built in since version 1.5.
There's three common methods of creating a String with the appropriate user ID in place, namely direct string concatenation, using a StringBuilder, or using String.format. I personally find using the String.format method to be the cleanest and tend to use it when applicable, but I recently began wondering how it actually performs against the other two methods.
While deploying Docker containers on Amazon's Elastic Beanstalk is about as easy as it gets, it can be a little tricky to debug the container. For example, you may want to tail the logs, or open a shell inside the container to see what's going on.
Given a future date, how can you update a TextView with a countdown timer to the date on Android? Pretty easily in fact, using a couple quantity strings, the TimeUnit class, and a Handler.
I've added Go as one of the supported languages in my XOREncryption repository, and I'd like to show just how easy it is to use.
The many previous versions of this blog always had an actual backend - from Grails, to Django, to Node.js - with an admin panel, database, CMS panel, etc. This meant that the application had to be deployed somewhere (Amazon EC2), the database had to be hosted and managed (Amazon RDS), and new posts required the use of a clunky interface I wrote ages ago and had no desire to update. hat I wanted, and what I ended up building, was something more dynamic.
I recently added a small package to my go-kit that provides the ability to execute a function after repeated time intervals. The package provides the ability for the time interval to be dynamic, meaning the delay is determined after each execution, or on a fixed interval.
Slices in Go are quite nice to work worth, but the standard library doesn't provide any way of creating a unique slice. Since this is such a common requirement, the community has come up with a few tricks to accomplish this, and I figured I'd share the one that is the most common, and perhaps simplest to write.
Like most languages, Go values small, reusable, self contained packages and functions that can be easily reused, tested, and modified. In order to accommodate this, I find the best thing to do is to create your own go-kit, a collection of small packages that each have a very specific purpose.
The Android TextView supports displaying a drawable beside, above, or below the text, but how do you programatically change the color of the drawable to match the text? Turns out it's actually really easy using a PorterDuffColorFilter, but a little obscured behind some silly documentation.
Last year was pretty good, but this year I've decided to step it up a notch and document 12 New Year's resolutions that I aim to accomplish throughout the year
IconEditText provides a reusable view for displaying an ImageView with an EditText for Android 4.0+.
A pretty standard setup these days is to have an application deployed on any number of EC2 instances in an Auto Scaling Group, behind an Elastic Load Balancer (ELB). The trouble is, how do you redeploy the application, with zero downtime, across the entire fleet of instances? In addition, how can we do this while maintaining the current number of healthy instances? Depending on your setup, the answer is actually pretty simple.
lambda-uploader is a Node.js module for uploading a source directory to AWS Lambda as a function.
When you're talking about auto scaling your applications, automating everything is key. That includes updating your source code, installing dependencies, starting your web server, etc. In this post, I'm going to walk you through setting up a Launch Configuration for your Auto Scaling Group that does just that.
Often times when starting a project, I want a simple, cost-effective, and custom tailored system for tracking user events. In order to solve that problem, I created Metroid.
Since Xcode 6, enterprise distribution has no longer generated the required P-List for distributing your iOS application. This tool handles generating it for you, and can be easily used as part of your Continuous Integration process when automating builds.
Sometimes you need to add or modify a sequence in PostgreSQL. Maybe you migrated your data from another engine, such as MySQL, and lost your primary-key sequence (Auto Increment in MySQL). Or maybe you simply need to modify the next value your sequence provides.
I've just published my iOS and Mac OS library for asynchronous image downloading, aptly named AsyncImageDownloader, to CocoaPods.
A common issue I have seen with various code snippets around the internet is that developers are unwittingly downloading images synchronously in iOS (or Mac OS for that matter) apps, causing the application to freeze as the main UI thread is blocked. This is poor practice for a number of reasons, but the main issue is that the app appears to be unresponsive while the image is downloaded. Depending on the connection of the device, this can severely harm the usability of your application.
SQLite is a public domain database engine that is designed to be incredibly minimal and simplistic, with a tiny footprint, making it a perfect candidate for mobile devices. Luckily for us, Android comes equipped with the database out of the box, and a very handy library for interacting with it.
I've been working on a very simple Android app that fetches and displays blog posts from my site. As I was developing the app, I decided that it would probably be of more use to show people the source code than to actually release the app on Google Play, seeing as how a mobile device isn't the greatest way to view code snippets.
Previously I wrote about how to animate views into place using a ListView on Android, similar to how Google does it in their Google Plus app. I decided to publish an Android library that manages the animations for you, allowing you to easily integrate it into any project.
Google Plus style ListViews are all the rage these days on Android because of the slick animations it displays when presenting data. When a user scrolls down, new items animate up into view, and quite frankly it looks awesome. In my latest app I decided to implement the same style animation, and it turned out to be very easy to implement. I also decided to implement an animation when scrolling up in the ListView so that the rows animate down into view.
This tutorial will cover how to fetch and parse JSON from a remote server on Android. We will use GSON, a JSON parsing library developed by Google, to quickly parse the JSON into Java objects with very minimal work required.
XOR encryption (or Exclusive-OR encryption) is a common method of encrypting text into a format that cannot be trivially cracked by the average person. XOR encryption is great for storing things like game save data, and other data types that are stored locally on a users computer, that while not a big deal if they are tampered with, you would like to deter people from doing so. XOR encryption is also used often as a part of more complex encryption algorithms.
A lot of times when starting a new Grails project (or any new project, for that matter), there is a lot of work done on user authentication and registration, role definition and permissions, and managing the authentication flow.
When developing for the web, many people use Google Analytics
to track, you guessed it, analytical data about users. While the tool is great at what it does, one problem that consistently comes up is the need to keep development analytics from being tracked.
Amazon recommends using a properties file to supply AWS credentials to your Java application, and while this is generally the most appropriate way to do it, what happens if you want to dynamically connect to different AWS accounts, or for whatever reason you need to provide the credentials in code?
Something that I recently needed to add for the admin panel and home page of this site's redesign was to order posts by the number of views it has. I was actually quite surprised to find that Grails doesn't inject this functionality as part of it's standard CRUD functions on domain classes, such as list and findByXAndY.
Everyone knows using the default font in an application can get a little boring. The new Roboto typeface in Android is all well and good, but it can leave something to be desired at times. Luckily, using a custom font is quite easy.
Recently I was parsing a REST API that returned data in JSON format, and noticed that this particular API formatted it's dates in a peculiar way:
Welcome to Part 1 of my Programming with Dart tutorial. In this series I will help you get started writing Dart code by teaching you the fundamentals of the language, and give you a little background on it as well. So, without further ado, let's get started.
Implementing a custom 404 page can be an effective way to retain visits from people who have found a dead link to your site, or have stumbled upon a page that doesn't exist. Depending on the content of the URL, you may even be able to show the vistor some links they may be interested in based on related content.
Like so many of the iOS UI components, the UITabBarItem is very easy to customize and manipulate. This post will show you how to add some basic customization to your tab bar, by defining custom images for each tab based on the state of the tab. By default, a blue tint is applied to the selected tab, but we can go further than that by completely changing the image, or applying our own tint to...
GORM provides Grails developers with plenty of useful hooks, events, methods, and functionality, not the least of which is domain events that inform you when domain objects are being created, updated, and deleted (you can find documentation on these events here). Within these events, a common use-case is to determine if a particular domain property has changed, and to act accordingly.
It seems that ever since Grails 2.1 arrived, controller classes have not been auto-reloaded when edited in a development environment. I'm not sure if this is now the intended behaviour of controllers, but it sure can make for slower development and debugging.
Something that can be helpful in Android development is to know if your app is in the background, or if it is presently active. Determining this programmatically can be tricky, but it is by no means impossible. Using your Application object, you can register a listener for activity lifecycle changes, and keep track of your application's state.
With all of the news about Google shutting down Reader on July 1st, there seems to be an uprising of new RSS feed readers cropping up to try and fill the void.
When using resources in an Android application, it is usually sufficient to make use the of resource manager with functions such as getString() and getDrawable(). Occasionally however, you will need to get the actual URI of a resource. The process is very easy, as the URI has a very sensible setup: android.resource://[package-name]/[Resource-ID] All you need to do is replace the package name with your app's package name, as defined in the manifest, and the resource...
Having the same content available at www.yourdomain.com and yourdomain.com is bad for SEO, because it counts as duplicate content. Not allowing users to go to www or root is even worse, as most users will simply assume the website is broken, or nonexistent. The solution is to redirect from one to the other, allowing users to go to whichever they prefer, and removing the issue of duplicate content. I prefer to redirect from www to...
I'm a firm believer that every developer, like a carpenter or artist, should constantly be trying to improve their toolkit. These tools should help you accomplish your goals in a way that works for you. Just like a single paintbrush doesn't suit every artist, not all tools will suit every developer.
Unfortunately, Android does not support viewing PDFs out of the box in a WebView. Luckily, Google has a nifty little tool that allows you to perform this very task quite easily using Google Docs. Basically we will embed our PDF in a Google Doc page on-the-fly and load that. Here's the code:
One of my favourite features of Grails is the ability to render just about any object as JSON. This makes the creation of REST API calls a breeze, but one problem with the default implementation is that it renders the entire object as JSON. This isn't always an issue, but if for example you are rendering a User object, you (hopefully) don't want to output the user's password. You may also wish to limit the...
A lot of times when using a REST API, it is effective to map integers from your JSON to an enum in your Java models. With Google's GSON library, the process of doing this is can be a little tricky, but I find it well worth the added effort to do so.
Something that is very common in user interface design is to have a repeating background image on your views. The image is normally very small, and repeats across your view's background to give it more texture or style than a flat background color. This trick is often used for simple gradients, providing better performance than programmatically drawing the gradient on the view, but it can also be used for textures or more complicated gradients to...
A common method of developing HTML5 applications for Android is to implement a native WebView and have it load your HTML5 web page. Using this method, the user is presented with what looks like a native application, because the 'browser' used to render your HTML does not have any of the standard browser buttons or the URL input. It simply loads your HTML with no other UI elements.
Welcome to my new site. If you ever took the time to look at the old site, first of all thank you, secondly you will know it was severely lacking. The design was mediocre at best, and it was all very static. I wanted to start getting into blogging again, and not just use this space to showcase some of my work.
Getting Started First off, lets get Python installed. If you are running a Linux distro you should already have it on your system. Run the command: python -V In a terminal to see if you have it. If not take a look around for how to properly install it on your system. Many Linux distros rely on Python, and a specific version at that, so you have to be careful not to ruin your OS's...