2d iPhone Games with UnityMy friend Jon Perry and I just released our first iPhone game,
Diabolika. It's a 2d puzzler and I used Unity 3d to create it. I figure a lot of people are interested in doing similar things on the iPhone with Unity, so now that I've been through the whole process I'll throw up a tutorial on it.
Even if you're not interested in Unity, you may find some helpful hints in here about the Apple Developer/App Store process, too. It's slightly mysterious.
Tools You'll Need:- A Mac
- An iPhone/iPod Touch
- Unity ($199 or $1499)
- Unity iPhone ($399 or $1499)
So yeah, the overhead is fairly expensive for an indie, especially if you go with Unity Pro/Unity iPhone Advanced, as I did. Thankfully, you can do a lot with a Mac and a Unity license. For me, it was a great initial investment, as my Macbook Pro is one of my primary development platforms and I plan on doing a lot with Unity in the future (both iPhone and non-iPhone). Unity already builds to Windows, Mac, iPhone, browsers, and Wii, and its developers are very active. You're getting a lot of bang for your buck.
IntroductionUnity 3d is a 3d engine and is not made for 2d games, so it does take a bit of finagling to get a 2d game working. That said, it's flexible enough to handle 2d, and it's intuitive enough that any game, 2d or 3d, can be built in a short amount of time. Diabolika was created in a little over a month, and much of that was spent learning how to do the things I'm going to summarize for you here.
Pros:- Fast development
- Can deploy 2d/3d games quickly
- Unity Dev Team is very active and responsive to developers
- Great community
Cons:- Larger file sizes (10 MB minimum, Diabolika is 16.3 MB)
- Not optimized for 2d
- Wouldn't suggest it for 2d games that are very complex or require a lot of sprites
Getting Set Uphttp://www.unifycommunity.com/wiki/index.php?title=IPhone_Getting_Started_with_the_UnityRemoteThis is a great tutorial that basically tells you how to get set up with the iPhone Developer Program, set up your app and iPhone for deployment, and eventually stream your game from Unity iPhone to your iPhone/Touch using Unity Remote.
Unity iPhone is a separate application from Unity 3d but it essentially works the same way.
Unity Remote is an app that runs on your iPhone/Touch that streams your game from the editor on the iPhone/Touch so you can see how it handles. Basically, you can run your game in Unity and it will then run on the phone. Unfortunately, because it's streaming, it will look blurry and will lag. I didn't use it much during development, preferring to just build the app onto my iPod Touch.
The App ID is confusing to most people at first. It's an ID that represents your app, and you have the choice of using a universal wildcard like "*" or using a backwards domain name (that you own) like "com.derekyu.*". The tutorial suggests you use a backwards domain name. Actually, with Unity, I think you HAVE TO do this.
Individual or company?One fairly major decision you'll have to make it whether you want to apply to the Apple Developer Program as an individual or as a company. Individuals cannot have more than one team member, but companies have a more rigorous application process where you have to prove that you're a company by sending in incorporation papers and what-not. As an individual you can still let other people test your game on their iPhones, however. They just can't be part of your "team."
I've heard it's not easy to switch back and forth, so you should be pretty settled on which profile you want before you sign up.
Sprite ManagerBrady's
SpriteManager is practically a necessity for 2d iPhone developers. Because of the overhead of Unity and the limitations of iPhone, even a small 2d iPhone game will quickly get slow. Here's the problem:
YOU CAN REALLY ONLY HAVE AROUND 20-30 DRAW CALLS OR LESS PER UPDATE BEFORE THINGS START TO SLOW.The first version of Diabolika used planes for sprites, and because I have an 8x8 board in the game, that meant potentially 64 draw calls at once, not including the explosions and GUITexts (for score and other info) that I was using (each considered a draw call).
SpriteManager lets you put all the sprites on a single "atlas" texture and then draws them onto a single mesh before drawing that onto the screen. That's 1 draw call for all your sprites instead of 1 for each! Huge save on overhead, right there.
In the end, I used a combination of Sprite Manager and planes to make Diabolika relatively speedy on the iPhone/Touch. Many thanks to Brady for this script, which is free to use. This is a great example of how cool the Unity community is!
2d AnimationIf you use Sprite Manager, you just switch the UV coordinates of a sprite to different frames of your animation. The function you want to use is:
PixelCoordToUVCoord(x, y)
You may also find this Javascript useful:
http://www.unifycommunity.com/wiki/index.php?title=Animating_Tiled_texture_-_ExtendedOptimizingUnity iPhone Game Development Tricks:
http://shohagsust.wordpress.com/2008/12/13/unity-iphone-game-development-tricks/Here are the main things you want to be optimizing:
Build Size- Unity will not include unused files in your final build and it will also flatten your Photoshop PSDs for you, so don't worry about that!
- Unity iPhone Advanced includes a "Build Stripping" option that can significantly reduce your file size by stripping out unused features (like physics, for example). Go to Project Settings -> Player -> iPhone Stripping Level and set it to "Strip Bytecode."
Load Time- If you can put multiple images onto a single, large texture, it will load faster than smaller individual textures. (Confirm!)
Overall Speed- Use SpriteManager
- Use PVRTC image compression
PVRTC image compression can look really bad... like, low-quality JPEG bad. I used compression on my backgrounds, but not on my characters.
PVRTC image compression only works on square textures, e.g. 256x256, 512x512
- Reduce the number of things you do in Update()
- Reduce the number of Update() calls (one is optimal)
- Go to Build Settings -> Player -> iPhone Script Call Optimization and set it to "Fast but no Exceptions"
SubmissionAvailability Date: I've heard that if you set this to a date before the app actually goes live, then you will not appear on the list of "new" iPhone games and will be starting late. As a precaution, I set it to 2 weeks after the submission date and rolled it back when Diabolika went out.
Pricing: Each price point is called a "tier." Tier 1 is $0.99, Tier 2 is $1.99, and so on.
Vendor Identification Number: This is just a number for you to ID your app with. It can be anything, as it's used for your own personal inventory.
Review Process: Diabolika was only in review for about 5 business days. We were fortunate to have made it through on the first attempt. Beta test the hell out of your apps.
Possible Rejection Reasons: http://stackoverflow.com/questions/308479/reasons-for-rejecting-iphone-application-by-apple-store...
WIP!