Frequently Asked Questions on Making Your First Game

January 26th, 2018

Filed under: Game Development | Be the first to comment!

I was recently doing some research on people new to game development for a possible project. A few questions cropped up repeatedly so I decided to answer them here.

What Engine or Library Should I use?

People new to game development often ask what game engine or library to use. There are a lot of game engines and libraries to choose from. The following six engines/libraries are suitable choices for someone making their first game:

The links provide good descriptions of each engine/library. I’m not going to rehash the material here.

If I had to recommend one engine or library for people learning to develop games, I would recommend Unity. It’s free until you start making $100,000(US) a year with your games. It runs on Windows and Mac. Unity is versatile, allowing you to make 2D and 3D games that run on iOS, Android, Windows, Mac, and Linux. Lots of people use Unity so there are numerous books, articles, and videos to help you learn how to use Unity. Unity also has a large asset store of tools, libraries, and artwork you can buy to speed up the development of your game.

When would you go with one of the other engines or libraries?

  • Use GameMaker if you want to make games without writing code.
  • Use Godot if you’re using Linux, or you want to use a game engine and don’t like Unity.
  • Use SpriteKit if you’re interested only in making 2D iOS games.
  • Use SDL or SFML if you have programming experience and have no need for a built-in tool to create game levels visually.

Don’t worry about making the wrong engine choice. If your initial choice isn’t working for you, choose a different engine. Suppose you start with Unity and struggle with writing code. You can switch to GameMaker, which doesn’t force you to write code.

What Programming Language Should I Use?

The language you use to write your game depends on the engine or library you use. If you choose Unity, you’re going to be writing code in C#. If you choose SpriteKit, you’re going to be coding in Swift or Objective-C. GameMaker and Godot come with their own scripting languages. SDL and SFML have support for more languages than the other game engines and libraries, including C, C++, Go, OCaml, Python, and Rust.

If you read the last section, I said SDL and SFML are for people with previous programming experience, which means you already know at least one programming language. Choose a language you already know so you can concentrate on learning SDL or SFML.

What Game Should I Make?

The specific game you choose to make is up to you. I’m going to provide one piece of advice on choosing your first game to make. Start with a small game, something you think you could finish in a week or two.

Making games is difficult. You’re going to make mistakes. It’s better to make those mistakes on a small game than on a massive game.


Checking Modifier Keys in Swift

January 22nd, 2018

Filed under: Cocoa, Mac Development | Be the first to comment!

Checking for modifier keys (Command, Control, Option, and Shift) when handling events is different in Objective-C and Swift. In Objective-C you perform a bitwise AND operation to check if modifier keys were held down. In Swift you check if the event’s modifier flags contains the specific modifier key.

The following example demonstrates how to check the modifier keys for a mouse down event in Swift:

override func mouseDown(with event: NSEvent) {
    if event.modifierFlags.contains(.command) {
        // Handle command-click
    else if event.modifierFlags.contains(.control) {
        // Handle control-click
    else {
        // Handle standard mouse click

Swift Functional Programming: Pure Functions

January 15th, 2018

Filed under: iOS Development, Mac Development | 2 comments

A pure function doesn’t reference any data outside of the function. If you supply a given input to a pure function, it always returns the same value. The following is a simple example of a pure function:

func increment(value: Int) -> Int {
    return value + 1

The increment function is pure because it increments the value you supply to it. It doesn’t modify any outside variables. If you pass the value 9 to increment, it always returns 10.

The following code is a hypothetical example of an impure function that updates contact information based on the values of text fields in an app’s user interface:

func updateContactInfo() {
    name = nameTextField.text
    address = addressTextField.text
    phone = phoneTextField.text

The updateContactInfo function is impure because it modifies variables outside of the function: name, address, and phone.

Pure Functions Simplify Unit Testing

A big advantage of pure functions is they’re much easier to unit test. To test the increment function, all you have to do is create an integer, call increment, and assert the incremented value is correct.

I know increment is a simple function, but unit testing any pure function follows the same steps.

  1. Create values for the arguments.
  2. Call the function.
  3. Assert the function returns the correct value.

Unit testing the updateContactInfo function would be painful. You would have to perform the following steps:

  1. Create an instance of the data structure that contains the contact information.
  2. Create, mock, or stub three text fields.
  3. Provide text for the three text fields.
  4. Call updateContactInfo.
  5. Assert the name, address, and phone number are correct.

Swift First Class Functions

January 12th, 2018

Filed under: iOS Development, Mac Development | Be the first to comment!

I considered writing an article about first class functions in Swift, but I came across the following article by John Sundell:

First class functions in Swift

Sundell’s article covers pretty much everything I would cover in an article on first class functions. The examples are good too. So I decided to link to his article rather than write my own.


Migrating to Bootstrap 4

January 9th, 2018

Filed under: Blog | Be the first to comment!

I am migrating this website from Bootstrap 2 to Bootstrap 4. Some things may look off due to the migration.