Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411526 Posts in 69381 Topics- by 58437 Members - Latest Member: GlitchyPSI

May 02, 2024, 01:34:44 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)Tutorials2d iPhone Games with Unity (WIP)
Pages: [1]
Print
Author Topic: 2d iPhone Games with Unity (WIP)  (Read 19656 times)
Derek
Bastich
Administrator
Level 10
******



View Profile WWW
« on: June 13, 2009, 04:55:08 PM »

2d iPhone Games with Unity

My 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.

Introduction

Unity 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 Up

http://www.unifycommunity.com/wiki/index.php?title=IPhone_Getting_Started_with_the_UnityRemote

This 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.

Quote from: PROTIP
Unity iPhone is a separate application from Unity 3d but it essentially works the same way.

Quote from: PROTIP
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.

Quote from: PROTIP
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 Manager

Brady'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 Animation

If 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:

Code:
PixelCoordToUVCoord(x, y)

You may also find this Javascript useful: http://www.unifycommunity.com/wiki/index.php?title=Animating_Tiled_texture_-_Extended

Optimizing

Unity 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

Quote from: PROTIP
PVRTC image compression can look really bad... like, low-quality JPEG bad.  I used compression on my backgrounds, but not on my characters.

Quote from: PROTIP
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"

Submission

Availability 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!
« Last Edit: July 20, 2009, 01:28:28 PM by Derek » Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #1 on: June 13, 2009, 05:15:51 PM »

I'm a bit confused about the prices you've given for Unity (or rather, the reason why Unity Pro/iPhone Advanced are required).  On the Unity shop page (https://store.unity3d.com/shop/) they list the indie license as $199.00 USD and the iPhone Basic license as $399.00 (upgradable from the indie license).

I assumed this is because iPhone Advanced would be required, but looking at the license comparison page (http://unity3d.com/unity/licenses), it seems like all the Advanced version has over the basic is "Improved Build Size Stripping".  Is this an essential feature?  Or is it something that Unity Pro has over Unity Indie that is essential? (In which case couldn't you get Untiy Pro + Unity iPhone Basic and save $1100.00 USD?)

The overhead could be drastically reduced if Unity Indie/iPhone Basic were usable.  Then I might actually be able to do this.
« Last Edit: June 13, 2009, 05:27:12 PM by Matt Thorson » Logged

Derek
Bastich
Administrator
Level 10
******



View Profile WWW
« Reply #2 on: June 14, 2009, 05:59:52 PM »

That's a good point.  Actually, I was under the mistaken impression that Unity iPhone required Unity Pro, regardless of whether you had the Basic or Advanced version.  Thanks for correcting me!

Build-size stripping is nice, because it reduces the size of your app significantly by removing features that you're not using from the final build (like physics, for example).

And then there's the "Made with Unity" splash screen... those things always bug me, but it may not be an issue with other people.

Anyways, I'll make that correction to my tutorial.  Thanks!
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #3 on: June 14, 2009, 07:34:28 PM »

Whew, I'm glad they aren't necessary!  That shaves a lot off the cost then.  Although the splash screen would bother me a lot, it's not worth the $2400 USD to get rid of it Tongue
« Last Edit: June 14, 2009, 10:01:49 PM by Matt Thorson » Logged

___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #4 on: June 14, 2009, 09:44:52 PM »

So does Unity just crap out for 2d games that would be pretty intensive?  I'm not going to be able to make a crazy bullet hell shmup with it or anything, right?
Logged
Alec
Level 10
*****



View Profile WWW
« Reply #5 on: June 14, 2009, 11:46:01 PM »

So does Unity just crap out for 2d games that would be pretty intensive?  I'm not going to be able to make a crazy bullet hell shmup with it or anything, right?

Depends how you do it. There are tricks and whatnot.
Logged

ChevyRay
Guest
« Reply #6 on: June 15, 2009, 12:32:00 AM »

Man, I wish I could make an iPhone game WTF

I have to learn to program for real-real, not just for play-play. Cool write-up, Derek. I know that I've heard questions popped (I accidentally typed "pooped" the first time) around more than occasionally that are probably all answered in this short post.

Props!
Logged
nihilocrat
Level 10
*****


Full of stars.


View Profile WWW
« Reply #7 on: June 15, 2009, 06:39:08 AM »

I assume a batch operation to draw 1000 bullets on the screen is considered to be a single draw call, but I don't really know anything about iPhone dev except the very basics.

Thanks a ton for the totoreal, Derek, shines light on a bunch of little details which are hard to see without actually working on an app.
Logged

Hayden Scott-Baron
Level 10
*****


also known as 'Dock'


View Profile WWW
« Reply #8 on: June 16, 2009, 04:27:17 AM »

its developers are very attractive

Fixed. :D  (I just picked up your app btw Derek!)

Yeah, Unity is pretty nice for 2D really, but it does require a decent amount of care. SpriteManager can help a lot but you can run into speed issues pretty easily if you're not careful.  Essentially you can't get away with the sloppy coding that PC development tends to allow, which is a nuisance for me, haha!

As for bullet hell, I think it would be okay to render hundreds of 2D bullets but the lack of proper d-pad would be a bigger problem.
Logged

twitter: @docky
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #9 on: June 18, 2009, 02:54:04 PM »

its developers are very attractive

Fixed. :D  (I just picked up your app btw Derek!)

Yeah, Unity is pretty nice for 2D really, but it does require a decent amount of care. SpriteManager can help a lot but you can run into speed issues pretty easily if you're not careful.  Essentially you can't get away with the sloppy coding that PC development tends to allow, which is a nuisance for me, haha!

As for bullet hell, I think it would be okay to render hundreds of 2D bullets but the lack of proper d-pad would be a bigger problem.

Yeah I was just speaking hypothetically about just having a crapload of sprites on screen.  Not necessarily for Unity iPhone specifically, but for PC/Mac development as well.  So having fancy particle effects composed of a lot of sprites, which is something I love, but it always ends up costing me!

I will be diving into the wild world of Unity soon enough.
Logged
Hayden Scott-Baron
Level 10
*****


also known as 'Dock'


View Profile WWW
« Reply #10 on: June 18, 2009, 11:59:23 PM »

It's probably worth pointing out that 'pixel perfect' 2D in Unity is pretty much impossible on anything other than the iPhone.  Something that looks precise on your screen using orthographic camera can look weird on other people's screens, often due to 3D hardware overrides or differences between graphics cards.

You can always oversize and scale down, or up if you prefer, but it's generally unwise to assume you'll be getting your stuff to be pixel perfect. You could theoretically do it with the GUI system but that's a whole different world of hurt.
Logged

twitter: @docky
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #11 on: June 25, 2009, 02:38:21 PM »

As for bullet hell, I think it would be okay to render hundreds of 2D bullets but the lack of proper d-pad would be a bigger problem.

cpu may also be a problem: calculating the movement and collisions of 1000 bullets 60 or 30 times a second would require a pretty tough cpu; what's the iphone cpu?
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #12 on: June 25, 2009, 02:39:17 PM »

found it:

Quote
Original & 3G: Samsung 32-bit RISC ARM 1176JZ(F)-S v1.0[7]
620 MHz underclocked to 412 MHz[8]
PowerVR MBX Lite 3D GPU[9]
3GS: ARM Cortex-A8
833 MHz underclocked to 600 MHz
PowerVR SGX GPU[10]

why do they underclock them?
Logged

JoeHonkie
Level 8
***


RIP Major Sebastian Bludd


View Profile WWW
« Reply #13 on: June 25, 2009, 02:40:33 PM »

found it:

Quote
Original & 3G: Samsung 32-bit RISC ARM 1176JZ(F)-S v1.0[7]
620 MHz underclocked to 412 MHz[8]
PowerVR MBX Lite 3D GPU[9]
3GS: ARM Cortex-A8
833 MHz underclocked to 600 MHz
PowerVR SGX GPU[10]

why do they underclock them?

Reduces heat and extends battery life.

EDIT: You'll notice your iPhone gets a little warm when you use it heavily.  Not uncomfortably so, but it was a huge difference from my Blackberry.
Logged
Hima
Level 4
****


OM NOM NOM


View Profile WWW
« Reply #14 on: July 12, 2009, 08:27:41 PM »

Wow thank you so much for sharing this. I'm really interested in developing game for iPhone. My college even open a class teaching developing software in iPhone but I couldn't take it because of the schedule clash *sigh*

Anyway, that's a lot of money to get start...I'll be getting my mac at the end of this month, but not iPhone and Unity Sad  Guess I should make games using other stuffs and sell them before I can start with iPhone. Also, I think you need to pay another $99 per year for app store, right?

As for the individual vs company thing, is it for Unity license or iPhone game?

Again, thank you so much for writing this. Gentleman
Logged

Derek
Bastich
Administrator
Level 10
******



View Profile WWW
« Reply #15 on: July 20, 2009, 01:27:25 PM »

As for the individual vs company thing, is it for Unity license or iPhone game?

That's for the Apple Developer Program itself. Smiley

I'll make that more clear in the tutorial.
Logged
hackdirt
Level 0
*


a


View Profile WWW
« Reply #16 on: August 18, 2009, 05:33:00 AM »

Hope no-one minds me resurrecting this thread, but I had a question about Unity and 2D iPhone games for Derek and it seemed appropriate to ask here.

I've downloaded a number of Unity-based iPhone games and it seems as if half of my playing time is spent waiting for the damn things to load their assets into memory. One particular game, Mevo, took about 15 seconds just to load the level selection screen, and then another 15-20 seconds to load the level when I made my selection! I know the iPhone platform is a special case and that resources are limited, but this just seems ridiculous to me.

Are you able to comment on this, in so far as loading times affect your particular game?
Logged
UntoldEnt
Level 0
**


View Profile
« Reply #17 on: August 18, 2009, 08:54:21 AM »

Hey - thanks for writing this piece!

Quote
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.

Be careful - that's a bit misleading.  It sounds like you're suggesting that with your Unity license, you can deploy to the Wii.  i spoke to the Unity guys at Casual Connect, and the Wii license is magnitudes more expensive than the iPhone or core engine license.  We're talking five figures.

- Ryan
Logged
Hayden Scott-Baron
Level 10
*****


also known as 'Dock'


View Profile WWW
« Reply #18 on: August 18, 2009, 10:43:44 AM »

I've downloaded a number of Unity-based iPhone games and it seems as if half of my playing time is spent waiting for the damn things to load their assets into memory. One particular game, Mevo, took about 15 seconds just to load the level selection screen, and then another 15-20 seconds to load the level when I made my selection! I know the iPhone platform is a special case and that resources are limited, but this just seems ridiculous to me.
There are ways to manage this, it really depends on whether it is a priority to the developer or the user experience in general. With Mevo there's a high likelihood that it is loading uncompressed music which will be quite slow.  It's difficult to sync gameplay with compressed music.

So, yeah, I don't thin Unity is to blame, but if you want to make a very lightweight app you would be better off working directly with the 2D Cocoa API.
Logged

twitter: @docky
Jason Bakker
Level 2
**


View Profile WWW
« Reply #19 on: August 21, 2009, 09:17:37 PM »

Derek mentioned in his tutorial that Unity 3D took a bit of effort to get working with 2D. I'm in the process of making a 2D iPhone game, and cocos2d has been a fantastic (and free!) solution for me, so I thought I'd put that forward as another possible option.

If you're interested, I did a quick writeup about my process of choosing an iPhone engine and why I ended up with cocos2d. If anyone has any further questions regarding cocos2d or iPhone programming, feel free to ask me, I'm usually lurking here these days while waiting for compiles to finish Wink

Ed: Oh, in regards to Bradley's Sprite Manager referenced in the tutorial, cocos2d also has that feature, and I'd concur that it is hugely important for keeping your framerate decent. A quick question for Derek - did you end up having every single sprite on one massive sheet and just Atlasing it, or did you still split it up a bit? (eg. enemy spritesheet, ui spritesheet, etc)
« Last Edit: August 21, 2009, 09:59:12 PM by Jason Bakker » Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic