Announcing: Prescription for Sleep

The first iPhone application I’ve worked on has just been released. It is called “Prescription for Sleep” – read this link for more background on the concept of the software. I should start by mentioning that unlike most of my work it is not a game. It is a music visualizer that is intended to act as a sleep aid. The application will take you from reading a mysterious book in your house, to space, to an alien world, and finally to a psychedelic representation of the womb. I programmed the application and designed and implemented the majority of the visualizers. I also did some art – woot, first published art work in a game!

The music was composed specifically for the application by Norihiko Hibino, prolific composer most famously known for composing the music to the Metal Gear Solid series. It was produced by Marc Cellucci at Mission-One. It was a fun group to work with and I’m happy to have had the opportunity.

Here is the link to the full version in iTunes: Prescription for Sleep on iTunes

There is a free version but it is not yet up on the iTunes store (the mysteries of the Apple approval process at work). As soon as it is I will post a link. The full version includes four visualizers and the free version features one of the four.

Working on the platform was a fun diversion from my Playstation 3 and Xbox 360 work. It was also enjoyable working “outside the box” so to speak on a non-game application.

I will post again soon with more technical details about what it was like working on the project and platform. For now here are some brief development stats:

Now with video

To record more of life’s occurrences, for both fun and for sharing with friends and family, yesterday I bought a Canon HF20 HD video camera. I haven’t had much time to play with it but did record a few scenes last night around my neighborhood.

I used Vimeo to upload the HD video. Vimeo has a great interface and looks like a quality service. Unfortunately, unless you are a paying member you cannot embed HD video into an external webpage. You can see the full HD version by clicking the link below the video and going to Vimeo’s webpage.


Ebisu, Tokyo, Japan. from Mark Cooke on Vimeo.

Releasing violent videogames in Japan

You may or may not be surprised to learn that in recent years (as of 2009) violent videogames have a hard time getting released Japan. When I say “released” I mean mainstream retail distribution. Personally, I was surprised and have seen overseas developers frustrated by it so I spoke with some local Japanese developers about the issue.

The common Western view is that other media in Japan – comics and anime cartoons in particular – are often extremely violent. So why can’t violent games be released? The last violent big budget game I shipped, Conan, did receive a Japanese release but with huge concessions and changes from the US release. The core gameplay feature was the combat system and a big part of the reward system built into it for the player was seeing Conan dispose of his enemies in an over the top way. We had to tone down the violence significantly right at the end of development to appease the Japanese game rating board, CERO, to receive an unrestricted release.

Of course I understand each country has a different culture and what is acceptable to one is off limits in another. The take away lesson for me, and what hurt the game, was that this was changed fairly late in development after the violence was already a key feature. Focusing on over the top gore and violence rewards in a game you intend to release in Japan (and Germany) is not a good focus of resources as those features will have to be reduced or cut hurting the core functionality of the game in the process.

When I asked the local developers about the issue they said that the restrictions have been slowly becoming more and more strict from around 1999 onward. Slowly and surely the criteria for getting rated CERO Z (restricted release, 18 and up only) are growing wider and wider. Publishers often wont bother releasing a game if it is expected to receive a Z rating. It is not quite the kiss of death that getting an Adults Only rating in the US is, which basically guarantees not being carried by any retail stores, but understandably publishers want games to reach the widest market possible for the highest sales potential.

But still – why the disparity between games and other media? The local developers think it has to do with the scrutiny the different media sources receive. As much as Japan is known for anime, in recent times games are much more in the forefront of day to day life. Nintendo advertises prominently in Harajuku station using an extremely popular fashion model (“Ebi-chan“). I can’t even remember the last time I saw anything anime being advertised in Tokyo outside of Akihabara or during television commercial breaks during the equivalent of Saturday morning cartoons. I see a lot more people playing DS and PSP on the train than I see reading comic books.

If that is the case then it is not surprising. The more public exposure a media generates the more independent parties are interested in it and the more politics enter into the equation. The bottom line is that as developers, if you want to have a prominent and wide release in Japan, focusing on violence as a core feature of your game is illadvised.

Flash sine wave fun

Simple but periodically pleasing. Click to randomly generate a new scene.


After Pause Talk vol. 29 last night when talking with just-arrived-in-Tokyo Brian Thomas the topic of algorithmically generated art came up. I spent five minutes and cooked this up. It was definitely fun and I want to explore it more. I need to go ahead and learn the Processing language which I’ve heard is great for this kind of stuff.

Full source code is below:

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;

	public class SinDraw extends Sprite
	{
		private var sinWaveData:Array;

	    [SWF(width=500,height=300)]
		public function SinDraw()
		{
			sinWaveData = new Array(200);
			onClick(null);

			stage.addEventListener(MouseEvent.CLICK, onClick);
		}

		private function generateWave():void
		{
			var amplitude:Number = 100 * Math.random();
			var frequency:Number = 0.0174532925 * 2; // 2 degrees in radians
			var phase:Number = 100 * Math.random();

			// intentionally goofy
			var r:uint = (255 * Math.random()) << 16;
			var g:uint = (255 * Math.random()) << 8;
			var b:uint = (255 * Math.random()) << 24;
			var color:uint = 0xff00000000 + r + g + b;

			for (var i:int = 0; i < 200; i++)
			{
				sinWaveData[i] = amplitude * Math.sin((i * frequency) + phase);
			}

			for (i = 0; i < 200; i++)
			{
				var index:Number = i * (500 / 200);

				graphics.beginFill(color, 1);
				graphics.drawCircle(index, sinWaveData[i] + 170, Math.random() * 5);
				graphics.endFill();
			}
		}

		private function onClick(e:MouseEvent):void
		{
			graphics.clear();

			var matrix:Matrix = new Matrix();
			matrix.createGradientBox(500, 300, 90);
			trace(this.width);

			// intentionally goofy
			var r:uint = (255 * Math.random()) << 16;
			var g:uint = (255 * Math.random()) << 8;
			var b:uint = (255 * Math.random()) << 24;
			var color:uint = 0xff00000000 + r + g + b;

			graphics.beginGradientFill("linear", [color, (color - 0xff222222)], [1, 1], [0, 0xff], matrix);
			graphics.drawRect(0, 0, 500, 300);
			graphics.endFill();

			generateWave();
			generateWave();
			generateWave();
			generateWave();
			generateWave();
		}
	}
}

Designing based on instinct vs. analytics

Andrew Chen has an interesting blog post up the dangers of the over use of A/B testing in product development.

In the commercial projects I’m working on I’ve been very much a proponent of testing game features, marketing material, etc. in a scientific way. As developers close to a project it is often very hard to know if what you are working on is going to resonate with your target market or not. When making a decision on a game feature with a passionate group there are often multiple view points about what is best and without a clear way to evaluate such decisions often the strongest personality in the room gets their way. This is designing by instinct and discussion. That isn’t always going result in the best decision for the game, hence my preference to use math and analysis to decide if it can be applied.

Testing variations of a feature against a large enough audience should ideally begin to reveal data that can concretely improve a feature if the test is designed correctly. As Andrew points out though this can result in overcompensated risk aversion and is better suited for small scale decisions rather than setting high level product direction.

In terms of game features specifically, I’m starting to incorporate more metrics into my applications so this type of data can be tracked by a database and data mined at a later time. I think this kind of tracking and optimizing of individual game features is a strong way of coming to a decision on game features that have no clear “best” solution.

New Design

Anyone who has been to this website before can plainly see there has been a large revision. In addition to a new design, I’ve replaced the Blogger back end with WordPress.

All of the old content has been migrated, including comments.

Comments and bug reports on the new design are welcome!

iPhone Development

Recently I’ve been working on the iPhone / iPod touch and my first title is nearly complete. I’ll announce it here soon and give some implementation details as well once it is finished.

Speaking generally about the platform, Apple has done an excellent job on the hardware as well as the API. It is easy to work with and the exceedingly low barrier to entry is why we’ve already seen countless applications released for the platform. Below is my list of the pros and cons of working with the device.

Pros:

  1. API is powerful, full featured, and well documented.
  2. The Instruments tool is very well done. Looking for performance bottlenecks, memory leaks, and analyzing general application behavior is a snap.
  3. Easy to test software in the iPhone simulator or directly on the device itself.
  4. Popularity has spawned some great open source work. I’m using cocos2d-iphone heavily in particular and have made a code contribution or two to that framework already.
  5. It is easy to get a product to market via direct distribution in the App Store.

Cons:

  1. Because of the pros listed above, especially #5, competition on the platform is insanely high. Getting an application noticed, regardless of quality, is a challenge. A lot of focus needs to be placed on getting your application noticed once it is released and everyone is fighting for that attention.
  2. Price competition has driven the average application price to $0.99. For most applications there is a very low glass ceiling on how much money it makes sense to invest in development. Selling 10,000 copies of an application you build yourself from scratch sounds great – and it is some nice exposure – but lets look at the numbers in a very rough way. At $1 a pop, Apple takes 30% (currently) leaving you with $7,000. Taxes, depending on your income and location, take perhaps another 20% of that. Now we’re at $5,600. For a professional developer working full time in the US with the skills to build an app themself, that’s around a months salary. Spending more than a month on the application then doesn’t make financial sense. But here’s the rub – most apps don’t sell anywhere near 10,000 copies. This severely limits the type of applications most developers can spend their time on.
  3. The X-Code IDE is decent but is nowhere near as nice as Microsoft’s Developer Studio. Especially when it comes to debugging.

Based on all of this my opinion on approaching the platform as an independent is the following: start small. Really small. Tiny ideas with focused, well implemented applications that target a specific niche without being too exclusive. Build up expertise and your own code library to start building applications faster and more efficiently.

Release these applications with boot-strapped marketing and PR. Put in the work to get the application’s name out there as much as you can. Track downloads and usage using tools like Pinch Media’s analytics platform. See what sticks. Once one of these small apps gains some traction, build on it. Understand why it is working well and give users more of what they want. Once you have a little cash flow and an understanding of what is working for you in the marketplace take the time to invest in and build something larger.

Finally, don’t rely on the iPhone completely for revenue. If your application is a game, ideally design it to take advantage of the platforms strengths but also work in other contexts. For example, a title that can both work in a browser under Flash as well as the iPhone gives you multiple revenue streams and more exposure. Unfortunately Flash and the iPhone do not share a common API or programming language, so it is a larger development investment, but the additional revenue and exposure opportunities for a small title are worth it in my opinion.

What kind of loan would you like?


What kind of loan would you like?

Want to borrow some money?

Better not go to “NO LOAN”.

Japan! Can we get a proof reader on advertisements with English please?

Abandoning Good Ideas

Working freelance on multiple projects simultaneously has caused me to think a lot about what is worth doing and what is not worth doing. My time feels shorter than ever – because it spread more thin – so focusing on the tasks of highest importance at all times is key.

Sometimes this is very hard to do. Especially if the task I am doing is useful, technically sound, and/or clever. But even if you are doing something that encompasses all of the above it still might not be worth doing… which can be a tough pill to swallow.

Here’s an example – I’m currently working on a project where graphics need to be sequenced to a music track. I created an XML definition for the sequencing so it is primarily data driven and created a little scripting language via XML tags for doing things like moving/scaling/rotating/fading/tinting sprites. It’s working great and dramatically sped up the initial sequencing.

While working with this further, I started to see lots of cut and pasted XML script to repeat the same kind of action. Just like cutting and pasting runtime code this is terrible for maintainability. I wanted to make subroutines for doing multiple combinations of moving/scaling/rotating/fading/tinting that could then be re-used in 1 line of XML to do something more complex. E.g., scale up an object, move it left 100 units over 2 seconds, tint it red, wait 2 seconds, then destroy it.

There were two clear ways to do this:

  1. Add new complex commands to the runtime code – hardcode a list of simple actions into a class that does something complex – and then expose them in XML. Still data driven but more specific to the use case and multiple of these would have to be added over the course of the project.
  2. Create a way to define these subroutines in the XML itself. This is more extensible and could then be quickly tweaked without recompiling the code.

Being in a “data drive everything” mood I chose the latter and went to create the ability to define a subroutine of commands in the same XML sheet the sequencing commands live in. Basically this was more or less creating a programming language with subroutine calls and passed parameters (albeit very limited in scope). You can define subroutines in XML that do a bunch of sequenced actions then call that subroutine from the XML in the sequencing block. This is far from the most difficult task I’ve completed as a programmer but it was definitely time consuming to set this up in a generic and parametrized way.

I just spent the last 8 hours working on it and I’m not sure it was worth the time. This is a small project and adding some extra subroutine types in a half-data driven half-hardcoded way may have been smarter as each individual case would have taken about 5 minutes to build (and the number of individual cases is unknown… maybe it is just a few!). If this framework was going to be re-used many times by many developers doing it the fully data drive way would have been worth it for sure. But for something that may end up being a one-off I think I should have waited before committing the time to this unless I was sure it was necessary. The agile programming method would have told me “do the simplest thing that will possibly work, refactor later if you need to” which I don’t think is correct 100% of the time but is correct the vast majority of the time.

Live and learn.

Finding Flash ActionScript 3 Resource Leaks

Even though programming in ActionScript 3 in the Flash engine gives you access to a garbage collected language it is still easy to leak resources and kill the performance of your application. I’ve been looking into some issues with an application I’m working on as well as general debugging techniques and wanted to summarize them in a post.

First, the two main resource leaks that have come up for me in game development:

  1. Leaking objects in the display list.
  2. Leaking event listeners, especially ENTER_FRAME.


Leaking display list objects

This is a straightforward leak that can happen to any DisplayObject you add to a DisplayObjectContainer. Even if the object is off screen, alpha is zero, or if its visible property is set to false the object is still being updated by the Flash runtime. It is using memory and CPU cycles. Make sure you clean up your objects by removing them from the display list when they are not in use.

Here’s a small, simple code snippet for recursively walking a display list. If you suspect a DisplayObjectContainer is leaking objects, you can use this small utility function to count how many display objects exist in all children. If it doesn’t go down at all, you may be leaking objects (of course it depends on the use case of your software).

public function walkList(obj:DisplayObjectContainer):Number
{
var result:Number = 0;
if (obj == null || obj.numChildren == 0)
{
return 0;
}

result += obj.numChildren;

for (var i:int = 0; i < obj.numChildren; i++)
{
result += walkList(obj.getChildAt(i) as DisplayObjectContainer);
}

return result;
}

Leaking event listeners

This can be harder to track down than leaking display objects. Here’s the big thing that may not seem obvious to people at first – removing an object from the display list, even such that there are no more references to it, does not automatically destroy it or any of its event listeners. If you add a listener through addEventListener() you must remove it through removeEventListener().

By far the worst case of this are rogue ENTER_FRAME events that are still executing on objects you think are removed and gone.

I spent some time trying to figure out how best to track these issues down. The AS3 event model allows you to, for most events, insert an event listener in a parent object in the display hierarchy and basically monitor events as they go by. For example, if one of your child objects has a MOUSE_DOUBLECLICK event you can put the same event on your stage with the third parameter to addEventListener() set to true (capture). You can then print out what object the event is actually going to by using Event.currentTarget inside of the stage event listener.

Guess what though? You can’t capture ENTER_FRAME events in that way. You’ll have to recursively walk the display list again looking for objects that have the ENTER_FRAME event registered. If they have no parent reference then they are likely orphaned (again, depends on your software use case).

Or perhaps better yet – don’t use ENTER_FRAME at all for complex Flash software and write a traditional game update loop. That’s what I’ve done in my engine. I now only use ENTER_FRAME for hacking together prototypes.

As an addendum, here are some gotchas regarding AS3 that I learned about in my recent research:

Apparently creating static utility functions, especially math helpers used in tight loops, is significantly worse performance wise than pasting the code into the loop (aka ghetto inlining) even if complex constants would have been precomputed in the helper. Lesson: static lookup is slow.

If you can avoid it, do not call functions on class references that are typed by one of their parent classes. E.g. if you have a variable of type MyObject, try not to reference it through the global root class Object or any other parent class that may exist. This defeats the purpose of object oriented programming in many ways but for your most performance sensitive code the virtual method table lookup destroys performance.