Bootstrapping to a Game Developer

This is a summary of the process of developing the game Kondrian.
battle2
You can see more on Kondrian here, or on iTunes here

Intro the indie

Half the world’s developers seem to be indie game developers, but I think there is a difference between developers who are already game developers who move to developing games on iOS, and those developers who are already developing on iOS and move into game development.

Based on the current number of games appearing in the store daily (148apps as many as 140 per day), there is a lot of game development going on.
Many of these seem to have been created by indie game developers, obviously indie game developers don’t need an introduction.

I however am coming from a different angle than most developers, a seasoned non game developer with a lot of experience on iOS, shipping my first ‘real’ iOS game (I’m not counting a kid’s game I wrote for a client because that was primarily UIKit and CoreAnimation, and much simpler).

Continue reading

Kondrian summary

Development summary for Kondrian

  • its Universal,
  • its written in Objective C (no C++),
  • home grown graphics engine (apart from the GLK* and OpenGL ES),
  • uses OpenGL ES 2.0, VBOs, VAOs and many other OpenGL ES 2.0 goodies,
  • uses GLKit, a GLKViewController and GLView – but uses standard OpenGL ES 2.0 shaders (just because they seemed slightly faster),
  • Continue reading

Kepa Auwae

This post has been sitting in the wings for at least 4 months. I delayed the posting until the Kondrian release.

One More Thing

Mid 2012, I attended the One More Thing conference.
One of the nice things that came out of this conference was some nuggets of wisdom from Kepa Auwae, he also had a very dry sense of humour.

Kepa is one of the founders of RocketCat Games.

Kepa’s stressed that his business strategy is always in flux, that RocketCat Games are always experimenting. They try to improve their business, by trying different things. One of his most interesting comments, was the description of a simple business model for game developers,  which is actually known to us all.

Continue reading

A potpourri of iOS game programming lessons 

The development of my game Kondrian is coming to an end.
title_big_iphone@2x

Here is a miscellany of what I think we’re useful lessons, each too small to warrant a blog post:

  • Each of the levels in Kondrian can be 100 x 100 tiles wide. It’s simple enough  to only draw the tiles when they are on screen, but I also created a scheme a bit like UITableviewCells in a UITableview in order to conserve memory. There are in fact only about 200 tiles (depending on whether its an iPhone or iPad) created, and they are reused when they go off screen. Reusing usually involves giving the tiles the appropriate texture for a tile potentially appearing onscreen in the direction that the player is moving.
  • All sprites (and the vertices, indices, VBOs VAs) are created at startup.
    When a sprite is needed it is de-queued and enabled, only enabled sprites are updated and drawn. No on the fly malloc-ing or creation of gl buffers.
  • Continue reading

Game AI and vectors using GLKit

Some famous game developer whose name I cannot remember (sorry about that whoever you are), said recently at a conference; that the AI of your game “enemies” can be a major part of the success and differentiation of a game. I don’t think you can instantly create great AI, it takes a lot of work, and for me its still “work in progress”.

So, I’ve been working on AI lately with the help of this excellent book as a reference.

This book is really good, not only for AI but also for anything to do with game movement.
Reading this book, suddenly made vector and matrix calculations make sense. And once they make sense its hard to use normal trigonometry again.

Below are some macro’s I’ve built with the help of the book.

Continue reading

Particle systems in IOS Game X

This is part six of a series on making iOS games.

Intro

With hundreds or thousands of particles on the screen, a particle effect is a great way to bring your frame rate precipitously down. There are so many different aspects of the particle engine that can effect performance.

Michael Daley has a whole chapter on this (see resources below – and he is right – its a big time sink).

I started off just extending the normal sprite classes which I created in the game template (which I talked about in the last post in this series), and then gradually moved to including more and more optimisations.

I (like everyone else) pre-create a number of particle engines, so that the expensive operation of memory allocation does not have to happen during the game, more as a precaution, than something I’ve rigorously tested with the profiler in Instruments.

Point sprites

Point sprites are a common thing to use with particles effects, to try an optimise things. With each particle as a point sprite you dont need to pass as much data to OpenGL, theoretically 1/6 of the data, since you are only passing one vertex per sprite, not two triangles.
In order to use point sprites you need to set the point size in the traditional vertex shader. I couldn’t see any docs on how to manage the point size in the GLKit base effect – this would be something like:  

gl_PointSize=32.0;

in the normal OpenGL ES 2.0 vertex shader.
So I experimented a bit and created a particle engine using the usual OpenGL ES 2.0 vertex and fragment shaders to do point sprites, and the same (as the game template in the previous post) GLKit base effect for the other sprites such as the player, background tiles etc.

Continue reading

The iOS Game Template extras

This is part five of a series on making iOS games.

Continuing on from last week, this post describes some of the non OpenGL parts of my iOS game template, and then finishes with some discoveries.

Centre of the universe

Since the player is the centre of the universe in my game, I can apply one translation to all my sprites.

Here is the simple translation I do:

GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(bounds.size.width * 0.5 - player->location.x, bounds.size.height * 0.5 - player->location.y, -6.0f);
spriteEffect.transform.modelviewMatrix = modelViewMatrix;

The z coordinate is arbitrary number – maybe I’ll use the z later at some stage.

ARC

Properties were great for memory management pre ARC – now of course ARC takes care of that, however in non games I still do tend to use only properties to access ivars. In a game I often do the opposite, I access the ivar directly, I try to avoid message passing. It can significantly deteriorate performance. With operations that are happening hundreds of times per second, messages (properties or methods), can hammer down the frame rate (I guess I could have my cake and eat it too, that is performance and classes by using C++. I don’t like C++, so I am not going to do that). Of course there is always a balance between performance and ease of use, so for my player sprite and monsters, I tend to use classes and instance methods, but for particles I use structs and functions.

Continue reading

The iOS Game Template setup

This is part four of a series on making iOS games.

Intro

A little while ago, I created a fairly generic OpenGL ES 2.0 game template (Xcode project) for a 2D game. It used standard vertex and fragment shaders. For this project I wanted to use GLKit effects, a GLKViewController (and it’s view) and storyboards.

So I used Ray Wenderlich’s excellent digital book “iOS 5 by Tutorials” to come up to speed. http://www.raywenderlich.com/store/ios-5-by-tutorials. Chapter 8&9 are the ones.

Ray’s tutorials will give you a good grounding in OpenGL for iOS 5, if you need that grounding. A bit OpenGL background might make this blog piece more interesting, because I won’t be explaining a lot of basic OpenGL things much (eg things like quads, shaders, vertexes, vertex structs, buffers etc).

In addition, Ray just recently came out with another tutorial on his excellent site which expands some on his previous OpenGL tutorials: http://www.raywenderlich.com/9743/how-to-create-a-simple-2d-iphone-game-with-opengl-es-2-0-and-glkit-part-1 and http://www.raywenderlich.com/9776/how;g-to-create-a-simple-2d-iphone-game-with-opengl-es-2-0-and-glkit-part-2.

Worth reading before reading the rest of this post

More challenging stuff

After setting up the initial story board, GLKViewController and GLKView, the next step for me was to add VAOs and VBOs (both of which Ray avoids in his most recent post).
Its fairly easy.

Here is my main VBO/VAO setup:

glGenVertexArraysOES(1, &vertexArray);
glBindVertexArrayOES(vertexArray);

glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER,spriteCount * 4 * sizeof(SmallVertex), vertices,GL_DYNAMIC_DRAW);

glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,spriteCount * 6 * sizeof(GLushort), indices,GL_STATIC_DRAW);

//vertex
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_SHORT, GL_FALSE,sizeof(SmallVertex), (const GLvoid *) offsetof(SmallVertex, Position));
//colour
glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_UNSIGNED_BYTE, GL_FALSE,sizeof(SmallVertex), (const GLvoid *) offsetof(SmallVertex, Color));
//texture
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT,GL_FALSE, sizeof(SmallVertex),(const GLvoid *) offsetof(SmallVertex, TexCoord));

Batching

One can scale the base case and just do hundreds of draw calls (each draw call with its own setup) – one for each sprite/image, but that might get slow, even if you packaged up into different VBOs/VAOs. If you had really complex shapes (3D models), you might have them in different draw calls because the shaders might make your scaling and transformations easier. The number of separate moving objects might be relatively low in a scene.

I just went straight to batching.

Continue reading

iOS Game X Technology

This is part three of a series on making iOS games.

I needed to decide on which technology to use in the game and a put down initial ideas on how elements in the game are to be structured.

Graphics Technology

I could write the game visuals using:

  1. UIKit
  2. Core Animation
  3. Third Party Framework
  4. OpenGL

1 and 2 are generally too slow for the 2D action game I am making (although I believe Core Animation is surprisingly fast and can handle hundreds of animating views on the screen).

My view on the third party issues is outlined below in a Napkin. I chose number four: OpenGL.

Continue reading