<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace V5 Site Server v5.13.166 (http://www.squarespace.com) on Thu, 20 Jun 2013 01:32:03 GMT--><feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><title>Nanaimo Studio Blog</title><subtitle>Our Blog</subtitle><id>http://www.nanaimostudio.com/blog/</id><link rel="alternate" type="application/xhtml+xml" href="http://www.nanaimostudio.com/blog/"/><link rel="self" type="application/atom+xml" href="http://www.nanaimostudio.com/blog/atom.xml"/><updated>2013-05-13T16:59:44Z</updated><generator uri="http://five.squarespace.com/" version="Squarespace V5 Site Server v5.13.166 (http://www.squarespace.com)">Squarespace</generator><entry><title>Dancing Android</title><id>http://www.nanaimostudio.com/blog/2013/5/13/dancing-android.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2013/5/13/dancing-android.html"/><author><name>Boon Chew</name></author><published>2013-05-13T16:59:01Z</published><updated>2013-05-13T16:59:01Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>A sneak peeak at a prototype we are working on</p>

<p><iframe width="420" height="315" src="http://www.youtube.com/embed/uX1FVMQXf5E" frameborder="0" allowfullscreen></iframe></p>
]]></content></entry><entry><title>Pack Your Texture</title><id>http://www.nanaimostudio.com/blog/2013/1/15/pack-your-texture.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2013/1/15/pack-your-texture.html"/><author><name>Boon Chew</name></author><published>2013-01-15T15:30:16Z</published><updated>2013-01-15T15:30:16Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><br /><br />
If you are actively developing games like us, you may be interested in checking out <a href="http://www.codeandweb.com/texturepacker">Texture Packer</a>, created by Andreas Löw.  It's a very well-made tool, we use it to fill all of our spritesheet needs.</p>

<p>TexturePacker is used not just for games, we use it when making <a href="https://itunes.apple.com/us/app/word-tracer-learn-chinese/id430413408?mt=8">Word Tracer - Learn Chinese</a> as well.  It's an essential tool if you want to save precious memory taken up by your assets. Check it <a href="http://www.codeandweb.com/texturepacker">out</a>.</p>


<p><span class="full-image-block ssNonEditable"><span><img src="http://d26bu41yhsbbx.cloudfront.net/img/texturepacker/spritesheet_in_20_s.jpg?__SQUARESPACE_CACHEVERSION=1358266154774" alt=""/></span></span></p>

<p>Disclaimer: Andreas is also the co-author for the book <a href="http://www.amazon.com/Learn-cocos2d-Game-Development-Apress/dp/1430238135">Learn cocos2d Game Development with iOS 5</a>, which we had the honor of doing technical review for.  We did this review based solely on the merit of the product.</p>
]]></content></entry><entry><title>Avatar Creator</title><id>http://www.nanaimostudio.com/blog/2013/1/9/avatar-creator.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2013/1/9/avatar-creator.html"/><author><name>Boon Chew</name></author><published>2013-01-09T14:49:24Z</published><updated>2013-01-09T14:49:24Z</updated><content type="html" xml:lang="en-US"><![CDATA[<br/><br/>
A sneak peak of our upcoming Avatar Creator app for iOS and Android.

<span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/avatars.png?__SQUARESPACE_CACHEVERSION=1357742998024" alt="avatar creator" width="700"/></span></span>]]></content></entry><entry><title>Unity 3D iOS apps with JOY(STICK)</title><category term="Unity3D"/><category term="arduino"/><category term="iOS"/><category term="idevblogaday"/><id>http://www.nanaimostudio.com/blog/2013/1/9/unity-3d-ios-apps-with-joystick.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2013/1/9/unity-3d-ios-apps-with-joystick.html"/><author><name>Zeng Le</name></author><published>2013-01-09T13:05:44Z</published><updated>2013-01-09T13:05:44Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>In the <a href="http://www.nanaimostudio.com/blog/2012/7/26/ios-games-with-joystick.html">last tutorial</a> , we used a joystick to control an iOS space shooter game, I hope you had fun with it.
This time around, we are going to use joystick to control a 3D iOS App made in Unity3D.
Here is a demo video of the final product.</p>

<iframe width="560" height="315" align="center" src="http://www.youtube.com/embed/rvVNJxILUr4" frameborder="0" allowfullscreen></iframe>

<h3>Assumptions</h3>

<ol>
<li>You are somewhat familiar with Unity's GUI. No previously coding experiences in Unity is assumed.  </li>
<li>You have heard about Arduino. No coding experience in Arduino required.</li>
<li>Basic Understanding of Objective-c &amp; iOS application development</li>
</ol>

<h3>The Big Picture</h3>

<p>The idea of this tutorial is to use an Arduino Joystick to wirelessly control a character in Unity 3D and run the app on iPhone. In order to accomplish this, there are several things we need:</p>

<ol>
<li><strong>Arduino</strong>: get joystick data and button data and broadcast it with UDP protocol.</li>
<li><strong>Xcode data receiving interface</strong>: Our Open Source RedButton API provides a delegate method to easily retrieve Joystick data broadcasted from the Arduino joystick.</li>
<li><strong>Unity Plugins for iOS</strong>: Once our iPhone receives the Joystick data, it need to send data from our Objective-c code to Unity code, so the joystick position can control the character in Unity.</li>
<li><strong>Unity 3D application</strong>: A character in Unity that can move forward, backward, left and right in response to our Joystick data.</li>
</ol>

<h3>Arduino</h3>

<p>This part is exactly the same as the <em>Hardware</em>, <em>Arduino program</em> section in the <a href="http://www.nanaimostudio.com/blog/2012/7/26/ios-games-with-joystick.html">previous blog</a>
You can upload the <a href="https://github.com/nanaimostudio/UnityJoystick">same code</a> (Under Arduino folder) to your arduino board. </p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/eg5rx/2012-07-15-16.50.09"><img style="max-width:638px" src="https://img.skitch.com/20120715-c8c6kycaxkj6id7g9px26qsed3.medium.jpg" alt="2012-07-15 16.50.09" /></a><br /></div>

<h3>Xcode data receiving interface</h3>

<p>The RedButton API is used to receiving Joystick data from Joystick.
This is an API we developed and used in our <a href="http://www.nanaimostudio.com/blog/2012/7/26/ios-games-with-joystick.html">[iOS Games with Joy(stick)]</a> tutorial.  Follow the <em>RedButton API Introduction</em> section in the blog if you haven't used it before.</p>

<h3>Unity Plugins for iOS</h3>

<p>One of the main issues you may ask is how do you send Joystick data to Unity. Luckily for you, Unity  describes a way to do just that in their official documentation. You can take a close look at Unity's build native code plugins for the iOS platform <a href="http://docs.unity3d.com/Documentation/Manual/PluginsForIOS.html">[here]</a>.
or you can follow the instruction below.</p>

<p>Three steps from the official documentations:</p>

<ol>
<li><p>Define your extern method in the C# file like follows:</p>

<pre><code>[DllImport ("__Internal")]
private static extern float FooPluginFunction ();
</code></pre></li>
<li><p>Set the editor to the iOS build target</p></li>
<li>Add your native code source files to the "Classes" folder</li>
</ol>

<p>In the RedButton API, we have defined several delegate methods to receive data from Arduino.
Now we just need to add a layer on top of RedButtonAPI layer so it can send messages to Unity.
Let's call this transition layer SendToUnity. The <strong>SendToUnity.h</strong> and <strong>SendToUnity.mm</strong> was defined for this purpose. SendToUnity Class is the transition layer: it sends data received from RedButtonAPI class to Unity.</p>

<p><strong>Let us apply those steps in this project:</strong></p>

<p>Here we use Joystick X axis data as an example to go through each line of code in both the Objective-C and Unity code. 
The Joystick Y axis data and the A,B,C buttons is similar to Joystick X axis data.
<em>The whole file of SendToUnity.h &amp; SendToUnity.mm file can be downloaded from <a href="https://github.com/nanaimostudio/UnityJoystick">[here]</a>(Under Xcode file folder)</em></p>

<ol>
<li><p>In Xcode, SendToUnity.h file add a float property x to save joystick x axis data.</p>

<pre><code>#import &lt;UIKit/UIKit.h&gt;
#import "RedButtonAPI.h"
@interface SendToUnity : NSObject&lt;RedButtonAPIDelegate&gt;
@property(nonatomic) float x;
@end
</code></pre></li>
<li><p>In SendToUnity.mm file</p>

<pre><code>#import "SendToUnity.h"
#define kJoystickCenterX 50
@implementation SendToUnity
@synthesize x;
-(id)init{
    if (self = [super init]) {
        RedButtonAPI *redButton = [[RedButtonAPI alloc] init];
        redButton.delegate = self;
    }
    return self;
}
- (void)joystickDataofX:(NSString *)xData Y:(NSString *)yData{
    self.x = [xData intValue];
}
@end


static SendToUnity *tmp = nil;


extern "C" {
    float RedButtonJoystickX(){
        if (tmp == nil) {
            tmp = [[SendToUnity alloc] init];
        }
            return (tmp.x-kJoystickCenterX)/kJoystickCenterX;
    }
}
</code></pre></li>
</ol>

<p>The SendToUnity.mm file defined a constant to store Joystick's center value.
In its init method, we instantiate a RedButtonAPI object and set its delegate to SendToUnity.</p>

<p>Then, joystickDataofX:Y: delegate is used to receive the axis data.
The last extern "c" part is necessary in order for Unity to call and get the return value.</p>

<p>Note that we use <em>(tmp.x-kJoystickCenterX)/kJoystickCenterX</em> equation to normalize the return value to a range between -1 to 1. </p>

<p>3.In Unity, if you want to call RedButtonJoystickX methods,
you need to defined it in the c# file like so:</p>

<pre><code>    [DllImport ("__Internal")]
    private static extern float RedButtonJoystickX();
</code></pre>

<p>The method can then be called as if it is an internal Unity method:</p>

<pre><code>    float fA = RedButtonJoystickX();
</code></pre>

<h3>Unity 3D application</h3>

<p>OK. Now the issue about send data from Joystick to Unity is solved, the next step is to build the Unity app.</p>

<p>In this app, we reused some source files from Unity's official tutorial called <a href="http://unity3d.com/support/resources/tutorials/penelope">Penelope</a>.
Speaking of which, If you are going to create a third person game in Unity, Penelope tutorial is really a MUST read.</p>

<ol>
<li><p>Download and import Resources file from [<a href="http://unity3d.com/support/resources/tutorials/penelope">Penelope tutorial</a>].</p></li>
<li><p>Create a new project named NewPenelope</p></li>
<li><p>Create a Plane via Unity->GameObject->Create Other->Plane.
Drag &amp; Drop the grass1TGA file onto Plane to set the grass ground.
Set Position to 0,0,0 &amp; Scale to 10,10,10 as the image below.</p></li>
</ol>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/ec7c8/screen-shot-2012-08-12-at-11.50.52-pm"><img src="https://img.skitch.com/20120816-1my5r31ype98iryu6prdg75526.preview.jpg" alt="Screen Shot 2012-08-12 at 11.50.52 PM" /></a><br /></div>

<ol>
<li><p>Create a Directional light via Unity->GameObject->Create Other->Directional light.
Make its position 0,0,0 and set its Rotation to 45,0,0</p></li>
<li><p>Create Player Object via Unity->GameObject->Create Empty.
Rename it to Player.
In the Project Objects folder, choose penelopeFBX. Drag &amp; Drop it onto Player to make it as Player's child object.</p></li>
<li><p>Now comes the fun part.  Let's add some scripts to our Player object.</p></li>
</ol>

<p>(1) Character Controller script</p>

<p>Select Player in the Hierarchy, then using Component->Physics->Character Controller
set the parameters as indicated in the screenshot below.</p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/ec7cq/screen-shot-2012-08-12-at-11.57.04-am"><img src="https://img.skitch.com/20120816-fdhe86rfns1yrpha28xhiwnrmu.preview.jpg" alt="Screen Shot 2012-08-12 at 11.57.04 AM" /></a><br /></div>

<p>(2) Animation Controller script</p>

<p>For this one, use the same script in Penelope tutorial named AnimationController.js. 
This script will be attached to the Player object. This script plays the appropriate animations 
for Penelope and blends the animations. It also uses the character’s movement direction to determine 
which animation should be played.</p>

<p>(3) Move script</p>

<p>This is the main script we are using to control the Character.</p>

<pre><code>    using UnityEngine;
    using System.Collections;
    using System.Runtime.InteropServices;
    public class Move : MonoBehaviour {
    //character variable stores the player
        public CharacterController character;
        //defined all objective-c side method as extern data
        [DllImport ("__Internal")]
        private static extern float RedButtonJoystickX();
        [DllImport ("__Internal")]
        private static extern float RedButtonJoystickY();
        [DllImport ("__Internal")]
        private static extern bool RedButtonIsButtonAPressed();
        [DllImport ("__Internal")]
        private static extern bool RedButtonIsButtonBPressed();
        void Start () {
            Screen.orientation = ScreenOrientation.LandscapeLeft;
        }
        void Update () {
        float fA = RedButtonJoystickX();
        float fB = RedButtonJoystickY();
        bool bC = RedButtonIsButtonAPressed();
        //use the Joystick X value to control Unity's X axis
        //use the Joystick Y value to control Unity's Z axis
        character.Move(new Vector3(fA,0,fB));

        //send a log output if button A is pressed.
        if(bC)
        {
            Debug.Log(bC.ToString());   
        }   
        }
    }
</code></pre>

<p>7.Add script to Camera</p>

<p>Add FollowTransform.js to Camera.
This script makes camera follow the player when the player is moving to a different position.
Here is the FollowTransform.js code:</p>

<pre><code>    var targetTransform : Transform;        // Transform to follow
    var faceForward : boolean = false;      // Match forward vector?
    private var thisTransform : Transform;
    function Start()
    {
        thisTransform = transform;
    }
    function Update () 
    {
        thisTransform.position.x = targetTransform.position.x;
        thisTransform.position.y = targetTransform.position.y+2;
        thisTransform.position.z = targetTransform.position.z-3.5;  
        if ( faceForward )
            thisTransform.forward = targetTransform.forward;
    }
</code></pre>

<p>This script sets the camera x as player x, camera y as player y + 2, camera z as player z - 3.5
so that the relative position of camera and player are always the same.</p>

<p>8.Make all connections <strong>IMPORTANT</strong></p>

<p>In Camera's Follow Transform (Script), set Player as target like this:</p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/ec7p9/screen-shot-2012-08-15-at-9.51.22-pm"><img src="https://img.skitch.com/20120816-bb88qf1y8m9irm5f92ynbk5dr3.preview.jpg" alt="Screen Shot 2012-08-15 at 9.51.22 PM" /></a><br /></div>

<p>In Player's Animation Controller, Character Controller, Move (Script)</p>

<p>Set all the connection and values as shown below:</p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/ec7qq/screen-shot-2012-08-15-at-9.54.37-pm"><img src="https://img.skitch.com/20120816-cgxfq5b8tbi1uiwg4u7mh1hrbq.preview.jpg" alt="Screen Shot 2012-08-15 at 9.54.37 PM" /></a><br /></div>

<h3>Summary: Steps to run the whole project</h3>

<ol>
<li>Upload  theArduino program to the Arduino board, make sure your connect Joystick Shield (top), WiFi Shield (middle), Arduino (bottom) in the right order and make sure the Red LED light is on (WiFi network is created)</li>
<li>In your iPhone WiFi Settings select RedButtonAPI</li>
<li>In Unity, click Build Settings, switch platform to iOS</li>
<li>Click Build &amp; run. It will open Xcode for you.</li>
<li>In Xcode, select Run on device.</li>
<li>That's it. It's time to use joystick to control your penelope.</li>
</ol>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/ec7up/camerarelativesetup.unity-newpenelope-iphone-ipod-touch-and-ipad"><img src="https://img.skitch.com/20120816-ffirj5xbdxtxtqaa1bh2fdwt41.preview.jpg" alt="CameraRelativeSetup.unity - NewPenelope - iPhone, iPod Touch and iPad" /></a><br /></div>

<p>All files for this project can be found from [<a href="https://github.com/nanaimostudio/UnityJoystick">GitHub</a>]</p>

<p>I hope you found this tutorial useful.</p>
]]></content></entry><entry><title>iOS Games with Joy(stick)</title><category term="arduino"/><category term="iOS"/><category term="idevblogaday"/><category term="idevblogaday"/><id>http://www.nanaimostudio.com/blog/2012/7/26/ios-games-with-joystick.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2012/7/26/ios-games-with-joystick.html"/><author><name>Zeng Le</name></author><published>2012-07-26T06:16:00Z</published><updated>2012-07-26T06:16:00Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><br/><br/>
Playing games using controllers is nothing new for gamers with iOS devices.  The controllers I am referring to are virtual joystick, accelerometer or gyroscope.  But let's face it, playing games with fingers sometimes just doesn't feel the same without the physical touches of a joystick (there is a reason why we call it JOY stick!). This is something I sometimes miss when I play games on the touch devices.</p>

<p>Fortunately, my college education hasn't gone to waste and it is being put to good use here.  Instead of putting up with the constraint, I say we make a <strong>real</strong> joystick for our iPhone today!</p>

<p>Let's start with our first goodie - the joystick. The joystick controller we are using in this project looks like this: </p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/eg5np/2012-07-15-16.14.08"><img src="https://img.skitch.com/20120715-jy6jrcesc67epww9ecqi47w8f8.preview.jpg" alt="2012-07-15 16.14.08" /></a><br /></div>

<p>Yes, we are using our lovely <a href="http://arduino.cc">Arduino</a> plus a WiFi Shield and a Joystick Shield.  Don't miss our previous <a href="http://www.nanaimostudio.com/blog/2012/6/2/mobile-tape-measure-using-ios-arduino.html">post</a> on using Arduino to build an ultrasonic tape measuring device if you haven't read it.</p>

<ul>
<li><a href="http://www.amazon.com/Arduino-Rev-3-Uno-R3/dp/B006H06TVG/ref=sr_1_1?ie=UTF8&amp;qid=1343002161&amp;sr=8-1&amp;keywords=arduino+uno">Arduino UNO board</a>: $20.49</li>
<li><a href="http://www.amazon.com/LinkSprite-CuHead-WiFi-Shield-Arduino/dp/B00789Z2TK/ref=sr_1_1?s=electronics&amp;ie=UTF8&amp;qid=1343002180&amp;sr=1-1&amp;keywords=arduino+wifi+shield">WiFi Shield</a>: $51.00 </li>
<li><a href="http://www.amazon.com/Arduino-Joystick-Shield/dp/B006LRRM3E/ref=sr_1_1?s=electronics&amp;ie=UTF8&amp;qid=1343002197&amp;sr=1-1&amp;keywords=arduino+joystick">Joystick Shield</a>: $21.95</li>
</ul>

<h3>Hardware</h3>

<p>Connect three shields together. </p>

<p>Three Shields: Arduino UNO (top left), WiFi Shield (top right), Joystick Shield (bottom)</p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/eg5rx/2012-07-15-16.50.09"><img style="max-width:638px" src="https://img.skitch.com/20120715-c8c6kycaxkj6id7g9px26qsed3.medium.jpg" alt="2012-07-15 16.50.09" /></a><br /></div>

<p>Attach the three shields together with JoyStick Shield at the top, WiFi Shield in the middle middle, Arduino at the bottom.</p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/eg5ra/2012-06-23-10.39.46"><img src="https://img.skitch.com/20120715-rthtbxahst44kuw29jn8p122ec.preview.jpg" alt="2012-06-23 10.39.46" /></a><br /></div>

<p>That's it!!!</p>

<h3>Arduino program</h3>

<p>You can download the Arduino code that performs the UDP broadcast from <a href="https://github.com/nanaimostudio/RedButton/tree/master/Arduino">here</a>.
In the git repo, there are two folders: RedButton API, WiShield.
Make sure you have the newest version of <a href="http://arduino.cc/hu/Main/Software">Arduino IDE</a></p>

<ul>
<li>Copy RedButton API to /Your local Arduino/ folder</li>
<li>Copy WiShield to /Your local Arduino/libraries/ folder</li>
</ul>

<p>Compile and upload RedButtonAPI file to your Arduion board</p>

<p>The Arduino code create a local network named "RedButtonAPI" and broadcast its status to the network via UDP port 1234. The output format looks like: "id=1111,1,1,1,50,49,"
<em>(The reason I add id field here is to help us detect reduntant data.)</em> 
"1,1,1,50,49" coresponds to the values from ButtonA, ButtonB, ButtonC, JoystickX and JoystickY.</p>

<p>You can download the joystick shield datasheet from <a href="http://iteadstudio.com/store/images/produce/Shield/Shields/itead_joystickshield/Joystickshield_DS.pdf">here</a>.</p>

<p>Here is the schematic of the joystick:</p>

<div class="thumbnail" align="center"><a href="https://skitch.com/zenglekidd/e8ghm/screen-shot-2012-07-17-at-11.23.51-am"><img style="max-width:638px" src="https://img.skitch.com/20120717-r8yds43gp93e2fmj9wnxtdg6ac.medium.jpg" alt="Screen Shot 2012-07-17 at 11.23.51 AM" /></a><br /></div>

<p>(Keep in mind which button is buttonA, buttonB or buttonC and the direction of Joystick X and Joystick Y)</p>

<p>To complete all pieces of the puzzle, let's look at how we use RedButton API to enable the communication between the hardware and our iOS devices wirelessly. </p>

<h3>RedButton API Introduction</h3>

<p><a href="https://github.com/nanaimostudio/RedButton/tree/master/RedButtonAPI">RedButtonAPI</a> is a static library that we created to enable communication between Arduino and any iOS device using the connectionless <a href="http://en.wikipedia.org/wiki/User_Datagram_Protocol">UDP</a> protocol.</p>

<p>NOTE: RedButton API was inspired by <a href="http://pitaru.com/">Amit Pitaru</a>'s work in the area of assistive technology.</p>

<p>You just need two steps to use this API. Create a instance of RedButton API class and set it up to receive controller values via its delegate method.</p>

<p>How to integrate RedButton API:</p>

<ol>
<li><p>Create a RedButtonAPI instance, set delegate to your self (self in this case is the HelloWorldLayer class)</p>

<pre><code>RedButtonAPI *redButton = [[RedButtonAPI alloc] init];
redButton.delegate = self;
</code></pre></li>
<li><p>Set up the delegate methods.
There are six methods you should be aware of:</p>

<pre><code>- (void)receivedRawDataFromArduino:(NSString *)data;
- (void)receivedRawDataFromArduinoWithRedundantCheck:(NSString *)data;
- (void)buttonAPressed;
- (void)buttonBPressed;
- (void)buttonCPressed;
- (void)joystickDataofX:(NSString *)xData Y:(NSString *)yData;
</code></pre></li>
</ol>

<p>In most use cases, you will just need last four methods. These methods tell you if A, B, C buttons are pressed and the current value of your joystick.</p>

<h3>Test driving RedButton API</h3>

<ol>
<li>Download the API from <a href="https://github.com/nanaimostudio/RedButton/tree/master/RedButtonAPI">github</a></li>
<li><p>Download the SpaceShooter Game code from <a href="http://d1xzuxjlafny7l.cloudfront.net/downloads/SpaceGame.zip">here</a>.</p>

<p>NOTE: Space Shooter is a <a href="http://www.cocos2d-iphone.org/">cocos2d</a> game developed by <a href="http://www.raywenderlich.com/">Ray Wenderlinch</a> for one of his cocos2d game tutorials.
Below is a video demo from <a href="http://www.raywenderlich.com/3611/how-to-make-a-space-shooter-iphone-game">Ray's tutorial</a> showcasing space shooter.  In this video you can see how the space shooter is being controlled via the use of tap and accelerometer.</p>

<iframe width="560" height="315" src="http://www.youtube.com/embed/-d4GsCt48ls" frameborder="0" allowfullscreen></iframe>

<p>Let's take it a step further and use our own joystick to control Ray's ship!</p></li>
<li><p>Drag two files (libRedButtonAPI.a, RedButtonAPI.h) into SpaceShooter Project, in Build Settings, set Compiler to <em>Apple LLVM compiler 3.1</em> </p></li>
<li>In <em>HelloWorldLayer.h</em>, import RedButtonAPI.h, add delegate declaration <RedButtonAPIDelegate></li>
<li>In init method of <em>HelloWorldLayer.m</em> , create an instance of RedButtonAPI, set delegate to self</li>
<li>In <em>HelloWorldLayer.m</em>, replace the <em>ccTouchesBegan:withEvent:</em> method with <em>buttonAPressed</em> method and keep the rest of the code intact. Essentially we are replacing the touch control with our joystick A button control.</li>
<li>In init method of <em>HelloWorldLayer.m</em>, comment out 
    self.isTouchEnabled = YES; </li>
<li><p>In <em>HelloWorldLayer.m</em>, we are going to use joystick to control the position of our space ship:</p>

<ul>
<li>Comment out accelerometer:didAccelerate: method</li>
<li><p>Add joystickDataofX:Y: method:</p>

<pre><code>- (void)joystickDataofX:(NSString *)xData Y:(NSString *)yData{
#define kJoystickCenterX 50
#define kJoystickCenterY 49
#define kMaxDiffX 0.2
int x = [xData intValue];
int y = [yData intValue];
_shipPointsPerSecY = (y-kJoystickCenterY)/kMaxDiffX;
_shipPointsPerSecX = (x-kJoystickCenterX)/kMaxDiffX;
}
</code></pre></li>
</ul>

<p>kJoystickCenter and kJoystickCenterY is the value of the physical joystick when the joystick is in its neutral position.
If the joystick is in the middle right position, we will calculate the X, Y offset and give a speed to the ship based on the offset value.  </p>

<ul>
<li><p>Comment out this line of code:
    //self.isAccelerometerEnabled = YES;</p></li>
<li><p>In init method after the definition of float maxY, float minY, replace them with the code block below:</p>

<pre><code>CGSize winSize = [CCDirector sharedDirector].winSize;
float maxY = winSize.height - _ship.contentSize.height/2;
float minY = _ship.contentSize.height/2;
float maxX = winSize.width - _ship.contentSize.width/4;
float minX = _ship.contentSize.width/4;
float newY = _ship.position.y + (_shipPointsPerSecY * dt);
newY = MIN(MAX(newY, minY), maxY);
float newX = _ship.position.x + (_shipPointsPerSecX *dt);
newX = MIN(MAX(newX, minX), maxX);
</code></pre></li>
<li><p>Add a variable in HelloWorldLayer.h file</p>

<pre><code>float _shipPointsPerSecX;
</code></pre>

<p>The purpose of this code is to set the boundary so our ship will always be within the visible area of our iPhone screen.</p></li>
</ul></li>
<li>In the update method, comment out this part:
    <div class="thumbnail"><a href="https://skitch.com/zenglekidd/eetw2/screen-shot-2012-07-23-at-11.19.59-pm"><img src="https://img.skitch.com/20120724-bg89i8xm33fjncyyy8mg911t3g.preview.jpg" alt="Screen Shot 2012-07-23 at 11.19.59 PM" /></a><br /></div>
    Comment out restartTapped method and endScene method and their corresponding code blocks. </li>
<li>Compile and run the code.  We can now move the space ship with our joystick!</li>
</ol>

<p>Time to check out our beautiful creation:</p>

<iframe width="560" height="315" align="center" src="http://www.youtube.com/embed/BFv9KgT1Mic" frameborder="0" allowfullscreen></iframe>

<p><br/></p>

<p>Here is the screencast showing the steps mentioned above:</p>

<iframe width="560" height="315" align="center" src="http://www.youtube.com/embed/I7dWwEFNvwg" frameborder="0" allowfullscreen></iframe>

<p>You can find all related files to this project from <a href="https://github.com/nanaimostudio/RedButton">github</a></p>

<p>Hope you enjoy the post. If you like what you are reading, subscribe to our RSS feed for more cool articles coming your way.</p>
]]></content></entry><entry><title>Nanaimo Studio Presents: Avatar Creator</title><category term="apps"/><category term="avatarcreator"/><category term="fb"/><category term="fun"/><id>http://www.nanaimostudio.com/blog/2012/7/9/nanaimo-studio-presents-avatar-creator.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2012/7/9/nanaimo-studio-presents-avatar-creator.html"/><author><name>Caroline Tan</name></author><published>2012-07-09T19:16:02Z</published><updated>2012-07-09T19:16:02Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/team-avatar.png?__SQUARESPACE_CACHEVERSION=1342614446194" alt="" /></span></span></p>
<p>The developers at this studio love making things that nobody else has thought of.&nbsp;There are lots of avatar creators or online avatar games on the internet - the more popular ones include the South Park avatar creator and Weeworld. Even though avatar creators are not something new to the world, we are thinking of revolutionizing it. We won't reveal too much about our final goal yet, but for now our <a href="http://www.apps.facebook.com/theavatarcreator">Avatar Creator</a>&nbsp;is the simple <a href="http://www.nanaimostudio.com/blog/2012/6/30/lean-software.html">lean software</a>&nbsp;that we have developed. Currently it is only available as a Facebook app, but we will continue to gather feedback, improve on it and take it to the next level and to different platforms. You can create your own beautiful avatar here: <a href="http://www.apps.facebook.com/theavatarcreator">www.apps.facebook.com/theavatarcreator</a></p>
<p>:)</p>
<p>And for those of you who think that avatar creating is useless and boring, we have included a few reasons as to why avatars are important to the internet culture:</p>
<p>1) Anonymity</p>
<p>With an avatar as a profile picture, you can remain anonymous yet at the same time allow people to feel personally connected to you through a warm and friendly avatar.&nbsp;</p>
<p>2) Personal branding</p>
<p>Your avatar can convey a lot about your personality (or your ideal personality anyways). If you use your avatars consistently and creatively people will remember you more easily and there is no need to painfully smile at a camera in attempt to capture the perfect image. Instead, you can just imagine it, build it, show it off to the world!</p>
<p>3) Broaden your mindset</p>
<p>It's fun to dress up different characters and to pick up different styling tips. Oftentimes, you may even learn a thing or two about different cultures and lifestyles, as scrolling through these different options exposes you to new things you may not have come across in real life before. It may even get your own creative juices flowing and inspire you in your next upcoming project.</p>
<p>So, what are you waiting for? <a href="http://apps.facebook.com/theavatarcreator">Create</a> your 100% free and beautiful avatar today! And remember to like our page or share it so that your friends can join in the fun too!</p>]]></content></entry><entry><title>Lean Software</title><category term="Development"/><category term="software"/><category term="thoughts"/><id>http://www.nanaimostudio.com/blog/2012/6/30/lean-software.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2012/6/30/lean-software.html"/><author><name>Boon Chew</name></author><published>2012-06-30T18:05:26Z</published><updated>2012-06-30T18:05:26Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>&nbsp;</p>
<h3><strong>Problem</strong></h3>
<p><strong>&nbsp;</strong>The world is filled with software with useless features and complicated UX like a pandemic.</p>
<h3><strong>Solution</strong></h3>
<p><strong>&nbsp;</strong>Look at all the existing software that you come into contact today. &nbsp;Pick out your favorites. &nbsp;Create a simpler versions of them by streamlining the essential features and cutting out all the unnecessary, fatty bits (aka useless features).</p>
<h3><strong>Results</strong></h3>
<ul>
<li>Your software gets done faster.</li>
<li>No more risk of it slipping the ship date.</li>
<li>No more burning midnight oil -&gt; Happier employees.</li>
<li>Less customer support hassles -&gt; Happier Users. &nbsp;You can always tell users who are crying for more features to go back to the fatty software.</li>
<li>No more trying to figure out which direction to take your company and what products to build. &nbsp;Just take what's out there and make it simpler and better.</li>
<li>Your software costs less to build (Free software anyone?)</li>
</ul>
<p><span style="font-size: 14px;"><strong>Make Lean Software&nbsp;</strong></span>- make this your new mission in your journey towards software craftsmanship starting today.</p>]]></content></entry><entry><title>Temple WTF</title><category term="AppStore"/><category term="iOS"/><id>http://www.nanaimostudio.com/blog/2012/6/27/temple-wtf.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2012/6/27/temple-wtf.html"/><author><name>Boon Chew</name></author><published>2012-06-27T04:41:48Z</published><updated>2012-06-27T04:41:48Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p>&nbsp;</p>
<p>A clear proof that an app icon is as important as (or sometimes more important than) the game itself. &nbsp;You saw it here first.</p>
<p><br /><span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/TempleRun.png?__SQUARESPACE_CACHEVERSION=1340762028698" alt="" /></span></span></p>]]></content></entry><entry><title>The Productive Apple Developer (Part II)</title><category term="idevblogaday"/><category term="idevblogaday"/><id>http://www.nanaimostudio.com/blog/2012/6/27/the-productive-apple-developer-part-ii.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2012/6/27/the-productive-apple-developer-part-ii.html"/><author><name>zitao</name></author><published>2012-06-27T04:41:20Z</published><updated>2012-06-27T04:41:20Z</updated><content type="html" xml:lang="en-US"><![CDATA[<p><br /></p>

<h2>Code Conventions, Uncrustify and others</h2>

<p>In the second part of this blog, I will continue to introduce some of my favorite tools for my daily development. The first thing I would like to talk about is coding convention. Check out the <a href="http://www.nanaimostudio.com/blog/2012/6/20/the-productive-apple-developer.html">first part</a> of the blog if you have missed it.</p>

<p>Good coding convention not only makes code much easier to read, it will improve the overall stability (See <a href="http://en.wikipedia.org/wiki/Broken_windows_theory">Broken Window Theory</a>). It will be difficult for me to cover all code styles in one post, so I will use Objective-C as an example.  </p>

<p>There are two coding conventions in Objective-C that I like, one is <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html">Introduction to Coding Guidelines for Cocoa</a> written by Apple. Another one comes from Google: <a href="http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml">Google Objective-C Style Guide</a>. Google's coding convention combined some conventions from Google's <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml">Open Source C++ Style Guide</a>. It covers more topics such like line length or comments style. Both of them are very good to read up on.</p>

<p>A wise man once says (OK I said it) "the biggest challenge for programming is to come up a good name for a variable or method". Often times I see developers fall into the temptation of naming things with numbers when they fail to come up with something sensible.  Don't do that - you will go to hell in your afterlife.</p>

<p>Following good coding convention is important, but it comes at a cost - it slows us down having to indent things or lining things up and developers don't like to be slowed down.  We are already trying to make our typing catch up with our thought stream. Luckily, the beauty of being in the software industry is that for every problem out there, someone is likely to have come up with a solution for it. <a href="http://uncrustify.sourceforge.net/">Uncrustify</a> is one such solution.  It is a tool to reformat all your code. It supports C, C++, C#, ObjectiveC, D, Java, Pawn and <span class="caps">VALA.</span> Here is how I use it:</p>

<ol>
<li>Select all code in Xcode </li>
<li>Press my assigned hot key: Control + Command + Shift + I</li>
<li><span class="caps">DONE.</span> All code are nicely formated. Amazing, no?</li>
</ol>

<h3>How to set up uncrustify?</h3>

<p>First, run following command to install uncrustify:</p>

<pre><code>sudo brew install uncrustify </code></pre>

<p>If you don't have brew command install, please refer to previous <a href="http://www.nanaimostudio.com/blog/2012/6/20/the-productive-apple-developer.html">post</a>. </p>

<ul>
<li>Next is to open Automator and create a new Service, the service it created is located at </li>
</ul>

<pre><code>~/Library/Services</code></pre>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/create_service_in_automator.png" alt="Create Service in Automator" /></p>

<ul>
<li>Add a Run Shell Script item, and using following command. Because the configure file (uncrustify_obj_c.cfg) is stored at ~/.uncrustify/, you probably need to create a folder for it and download the <a href="http://nanaimo.webfactional.com/static/blog/macguide/uncrustify_obj_c.cfg">cfg file</a>. If you don't have that folder, please create one. You can use your own configuration file and your own path, you just have to let uncrustify knows it. There are lots of work in configuring due to too many options there. I have spent hours on it and I would hate for you to go through the same fate. Download the file and use it as you wish. <br />
<a href="http://nanaimo.webfactional.com/static/blog/macguide/uncrustify_obj_c.cfg">Download Uncrustify Configuration File</a></li>
</ul>

<pre><code>#!/bin/bash
/usr/local/bin/uncrustify -l OC -q -c ~/.uncrustify/uncrustify_obj_c.cfg</code></pre>

<p><a href="http://nanaimo.webfactional.com/static/blog/macguide/Reformat.png"><img src="http://nanaimo.webfactional.com/static/blog/macguide/Reformat-1.png" alt="Reformat" /></a></p>

<p><a href="http://blog.carbonfive.com/2011/03/10/code-formatting-in-xcode-4/">Jonah Williams</a> provide a method to reformat <strong>all opened files</strong>. I don't like it - I have this innate fear that I am putting all my code in jeopardy. Go for it if you suffer no such psychological barrier. </p>

<ul>
<li>Save and use it. Select all your code, and go to Xcode -&gt; Services -&gt; Uncrustify(Your script name) <br />
<img src="http://nanaimo.webfactional.com/static/blog/macguide/services_menu.png" alt="Create Services" /></li>
</ul>

<ul>
<li>You can also assign a shortcut for it in the Xcode &gt; Services &gt; Text menu. <br />
<img src="http://nanaimo.webfactional.com/static/blog/macguide/Keyboard-1.png" alt="Add shortcuts" /></li>
</ul>

<p>Here comes the stunt, select a chunk of code and press Control + Command + Shift + i.  Good job Houdini!</p>

<h2>Automating TestFlight Upload</h2>

<p><a href="https://testflightapp.com/">Testflight</a> makes distributing our test builds easy. You can get more details on TestFlight <a href="http://www.nanaimostudio.com/blog/2011/11/10/beta-testing-ios-apps-made-easy.html">here</a>. But uploading to Testflight gets tiresome really quick (sorry TestFlight, yes we are that lazy). It's a repetition of clicking, waiting, click waiting, wait clicking, you get the idea. Luckily, this too can be fixed. Thanks to <a href="https://github.com/noodlewerk/NWTestFlightUploader"><span class="caps">NWT</span>estFlightUploader</a>, you can use it to upload to TestFlight in Xcode with just a few clicks. If you find even doing this is too much, it's time to look for another job.</p>

<p>For those of you who are still sticking around, here is what you do (I will show you how to install the tool after this):</p>

<p>1. After you install <span class="caps">NWT</span>estFlightUploader, you will see an upload dialog after you do an archive on your app.</p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode.png" alt="" /></p>

<p>2. Select signing identify</p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-1.png" alt="" /></p>

<p>3. Select provisioning profile, if you want to overwrite. </p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-2.png" alt="" /></p>

<p>4. Add notes.</p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-3.png" alt="" /></p>

<p>5. Choose Distribution lists.</p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-4.png" alt="" /></p>

<p>6. Send Email Notification?</p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-5.png" alt="" /></p>

<p>7. Confirmation.</p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-6.png" alt="" /></p>

<p>8. The uploading process will show up in the Console application. A dialog will also pop up after upload is finished. </p>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/testflight.log.png" alt="" /></p>

<h3>How to setup</h3>

<p><a href="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-7.png"><img src="http://nanaimo.webfactional.com/static/blog/macguide/Xcode-7-1.png" alt="Setup Upload to Testflight in Xcode" /></a>
* Edit the Scheme of your product in Xcode4<br />
* Expand the "Archive" scheme<br />
* Click "Post-actions"<br />
* Add a "New Run Script Action"<br />
* Select the target that corresponds to the Scheme in the "Provide build settings from..." dropdown<br />
* Copy &amp; paste the contents of <span class="caps">NWT</span>estFlightUploader.sh into the text field<br />
* At minimum, supply <a href="https://testflightapp.com/account/"><span class="caps">API</span>_TOKEN</a> and <a href="https://testflightapp.com/dashboard/team/edit/"><span class="caps">TEAM</span>_TOKEN</a>.<br />
* Done! To try it out, build the Archive scheme. At the end of the process the TestFlight upload 'wizard' will start.</p>

<h2>Color, Themes, and Fonts</h2>

<p>After two very nerdy topics, let me introduce some pretty stuff to please you right brainer out there. In our daily development, a large part of the time is dealing with editors such as Xcode, Sublime text 2, Textmates, etc. If we stare at a window with white background and black text, it's very easy for your eyes to get tired. So let me be your eye doc for a few minutes and show you my choice of colors and fonts and you can pick yours.</p>

<h3>Fonts</h3>

<p>For fonts, I will present you a list of my favorites. I've tried each of them at least one month so I know they work. I've tried many many other fonts, but most of them only last few days. The screenshot is using font size 16, because I want you to see the fonts clearer. If you use it, I would recommend to set your font size 13 to 16. For Anonymous (my most favorite font), I think setting the font size to 13 and 14 are probably the best. </p>

<p><a href="http://www.ms-studio.com/FontSales/anonymouspro.html">Anonymous Pro</a> It is my new favorite, very clean and elegant font.<br />
<img src="http://nanaimo.webfactional.com/static/blog/macguide/font2-1.png" alt="Anonymous" />
<a href="http://dejavu-fonts.org/wiki/index.php?title=Main_Page">DejaVu Sans Mono</a> The first font I used and I've used it for almost a year before giving up. I'm tired to look at the font over and over again lol.<br />
<img src="http://nanaimo.webfactional.com/static/blog/macguide/font3-1.png" alt="DejaVu" />
<a href="http://www.microsoft.com/en-us/download/details.aspx?id=17879">Consolas</a> It will appear after you installed Microsoft Office. This font looks very similar to Dejavu font.<br />
<img src="http://nanaimo.webfactional.com/static/blog/macguide/font4-1.png" alt="Consolas" />
<a href="http://www.levien.com/type/myfonts/inconsolata.html">Inconsolata</a> Many people recommend this font. It is a great open source font with a cool name.<br />
<img src="http://nanaimo.webfactional.com/static/blog/macguide/font1-1.png" alt="Inconsolata" /></p>

<h3>Color and Thems</h3>

<h4><span class="caps">EGO</span></h4>

<p>In the past, <a href="http://developers.enormego.com/view/ego_xcode_theme_for_xcode_4_egov2"><span class="caps">EGO</span></a> is my favorite. But after using for about one year, I finally realized I don't like the dark background and the stark contrast. <br />
<img src="http://nanaimo.webfactional.com/static/blog/macguide/themeeco-2.png" alt="EGO" /></p>

<p>To install the themes, run the following shell command in Terminal:</p>

<blockquote><p>mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes; cd ~/Library/Developer/Xcode/UserData/FontAndColorThemes; curl -O http://developers.enormego.com/assets/egotheme/EGOv2.dvtcolortheme</p></blockquote>

<h4>Solarized</h4>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/Solarized2.png" alt="Solarized" />
The color picked and the theme in <a href="http://ethanschoonover.com/solarized">Solarized</a> is elegant and pleasant. I found my eyes in a blissful state while looking at code in Solarized. Solarized uses a sixteen-color palette. It is a very interesting project and has support for Vim, Emacs, IntelliJ <span class="caps">IDEA,</span> NetBeans, TextMate, <span class="caps">BBE</span>dit, Visual Studio, and Xcode. But the support for Xcode is not that good. The color from it just don't feel right and bothers me for a long time. You can download the official at <a href="https://github.com/brianmichel/solarized/tree/master/apple-xcode4-solarized">solarized official github</a>. Or <a href="https://github.com/caoer/solarized">my version of Solarized Theme</a> or use following shell command to install it. </p>

<blockquote><p>mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes; cd ~/Library/Developer/Xcode/UserData/FontAndColorThemes; curl -O http://bit.ly/Solarize</p></blockquote>

<p><img src="http://nanaimo.webfactional.com/static/blog/macguide/solarized3.png" alt="Solarized" /></p>

<h3>Summary</h3>

<p>Consider a normal Objective-C file with 500 lines of code. Uncrustify can save 10 mins of manual code formatting. Automating your Testflight submission saves you another 10 mins from having to upload and distribute manually (If you use web version, you have to wait until file has been uploaded so you can distribute). With good code syntax color and a beautiful font, I don't know how much time it can save for daily coding and debugging process and potential visit to your doctor for migraine. So there you have it! I hope the above tips not only make you a productive but also healthier and happier coder.  In the next post, I will introduce even more tips to optimize your workflow to the next level. Please <a href="http://www.nanaimostudio.com/blog/rss.xml">subscribe</a> our blog to get more valuable tips!</p>
]]></content></entry><entry><title>The Productive Apple Developer</title><category term="Apple"/><category term="idevblogaday"/><category term="idevblogaday"/><category term="productivity"/><category term="tools"/><id>http://www.nanaimostudio.com/blog/2012/6/20/the-productive-apple-developer.html</id><link rel="alternate" type="text/html" href="http://www.nanaimostudio.com/blog/2012/6/20/the-productive-apple-developer.html"/><author><name>Boon Chew</name></author><published>2012-06-20T23:31:15Z</published><updated>2012-06-20T23:31:15Z</updated><content type="html" xml:lang="en-US"><![CDATA[<h2>Introduction</h2>

<p>In this guide, I would like to take the opportunity to introduce some tools and techniques to dramatically improve your productivity developing for Mac and iOS. Many of these techniques are something I use on a daily basis and they have helped reduce a lot of repetitive and mundane tasks and make me an ever happier Apple developer. This is called applying the <span class="caps">DRY </span>principle from code to OS tasks. For example, if you find yourself renaming multiple files into "duck1.png" and "duck2.png" and so on, something is wrong. We Apple developers should never ever repeat ourselves, since we are too busy playing the next gadget from Cupertino, right?  Without further delay, let's get started shall we?</p>

<h2>Terminal</h2>

<p>Terminal is a program included with all versions of Mac OS X. It is located in the Utilities folder within the Applications folder. When launched, it provides a line interface to control the underpinnings of the <span class="caps">UNIX </span>based operating system. The default <span class="caps">UNIX </span>shell in Mac OS X Panther (10.3) or later is Bash.</p>

<p>For a developer, terminal is arguably one of the most important tools in Mac.</p>

<h3>iTerm 2 - Terminal on Steroid</h3>

<p><a href="http://www.iterm2.com/">iTerm 2</a> is my favorite replacement for the default Terminal application. It is highly customizable and has many supports like tabs, colors, profiles and custom key bindings. If you are used to moving from word to word in Xcode, or other editors by using "Option + Left Arrow/Right Arrow", rejoice! Because you can set up these same behaviors in iTerm 2 with little effort:</p>

<ol>
<li>Go to Bookmarks &gt; Manage Profiles.</li>
<li>Expand Keyboard Profiles and click Global.</li>
<li>Click the + (Add Mapping) button.</li>
<li>Choose cursor left from the Key drop down menu.</li>
<li>Select the Option Modifier checkbox.</li>
<li>Choose send escape sequence from the Action drop down menu.</li>
<li>Enter b and click <span class="caps">OK.</span> You can now use Option-Left Arrow to move left/backward from  word to word.</li>
<li>Click the + (Add Mapping) button again.</li>
<li>Choose cursor right from the Key drop down menu.</li>
<li>Select the Option Modifier checkbox.</li>
<li>Choose send escape sequence from the Action drop down menu.</li>
<li>Enter f and click <span class="caps">OK.</span> You can now use Option-Right Arrow to move right/forward from word to word.</li>
</ol>

<h3>Brew, Homebrew</h3>

<p>Homebrew provides a straightforward and flexible way to install <span class="caps">UNIX </span>tools that are not included with <span class="caps">OSX.</span></p>

<p>In short, <a href="http://mxcl.github.com/homebrew/">Homebrew</a> is a Mac version of apt-get, gem, or aptitude. It manages <span class="caps">UNIX </span>tools. If you are terminal user, after using Homebrew your life will be forever changed. In fact, I bet you can't stop using it after you tried. Other similar package management systems in Mac are <a href="http://www.macports.org/">MacPorts</a> or <a href="http://www.finkproject.org/"><span class="caps">FINK</span></a>. I don't like these as much because they are outdated and unstable. </p>


<p>Installing Homebrew is simple:</p>

<pre><code>/usr/bin/ruby -e &quot;$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)&quot;</code></pre>

<p>Examples of using brew to install softwares:</p>

<pre><code>$ sudo brew install wget
$ sudo brew install git
$ sudo brew install curl
$ sudo brew install git bash-completion</code></pre>

<p>Things move pretty fast in brewland. If you don't update your brew after 24 hours, you will get a warning message. Update method is just what you can imagine:</p>

<pre><code>sudo brew update</code></pre>

<h3>iTerm 2 with Finder: Go2Shell</h3>

<p>What's your most used Terminal command? I bet it is "cd bala bala". Your situation goes like this: you open your good friend Finder, go to your project folder, coding, open iTerm 2(I hope you are using it now, :)), <strong>cd ~/balabala/myproject/</strong>, and do git. Using "cd" all day long is absolutely the most annoying thing. <a href="http://itunes.apple.com/us/app/go2shell/id445770608?mt=12">Go2Shell</a> is much simpler.</p>

<pre><code>Go2Shell opens a terminal window to the current directory in Finder</code></pre>


<p><span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/macguide/Go2Shell.png?__SQUARESPACE_CACHEVERSION=1338246599320" alt="Go2Shell"/></span></span></p>

<h3>Customize your .bashrc</h3>

<p>I personally like Bash more than the others, but if you are using sh or zsh, the idea is the same - take the time to customize your own profile to make your workflow more efficient. It is located in ~/.bashrc. It is the first to load when you open your iTerm 2 window. Use alias command properly to reduce the heavy loads. Alias just replaces a word by another string. Some examples:</p>

<pre><code>alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias sshc='ssh root@www.nanaimostudio.com'
alias cdo='cd ~/Documents/Projects/OpenSourceProjects/'
alias cdp='cd ~/Documents/Projects/'
alias s='subl'</code></pre>

<p>There are lots of tutorials talking about how to customize your bash. I will show a few of my own here because it would take a very long chapter to introduce all of them. </p>

<p>Don't put duplicate lines in the history.</p>

<pre><code>HISTCONTROL=ignoredups:ignorespace</code></pre>

<p>Append to the history file, don't overwrite it</p>

<pre><code>shopt -s histappend</code></pre>

<p>For setting history length see <span class="caps">HISTSIZE </span>and <span class="caps">HISTFILESIZE </span>in bash(1)</p>

<pre><code>HISTSIZE=1000
HISTFILESIZE=2000</code></pre>

<p>Check the window size after each command and, if necessary, update the values of <span class="caps">LINES </span>and <span class="caps">COLUMNS.</span></p>

<pre><code>shopt -s checkwinsize</code></pre>

<p>Set variable identifying the chroot you work in (used in the prompt below)</p>

<pre><code>if [ -z &quot;$debian_chroot&quot; ] &amp;&amp; [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi</code></pre>

<h4>Some tricks you might like</h4>

<p>I can't help to talk about the following tricks. It might be a little off topic so I will go as quickly as possible. These are very good tricks.</p>

<ul>
<li><strong>cd -</strong> takes you to the previous directory you were in.</li>
<li><strong>!!</strong> repeats your last command. Most used in the form of "sudo !!"</li>
<li><strong><span class="caps">ESC</span> .</strong> insert the last arguments from your last bash command.</li>
<li><strong>ls -thor</strong> list the most recently modified files in a conveniently readable format.</li>
<li><strong>history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head</strong> top 10 commands used.</li>
<li><strong>pushd</strong> and <strong>popd</strong> almost always come in handy</li>
<li><strong>for file in *.wav; do lame "$file" "$(basename "$file" .wav).mp3" ; done;</strong> Loop</li>
</ul>

<h2>Finder or Path Finder</h2>

<p>The original Finder is not very good. It is elegant indeed, but not that convenient. If you have ever used <a href="http://www.ghisler.com/">TotalCommand</a>, you will know how powerful a file manage software can be. <a href="http://cocoatech.com/pathfinder/">Path Finder</a> offers additional capability and control. It is a commercial software and costs $40. I have tried it few times - Path Finder is a great software and worth the price, but I like the simple Finder window more. It is just a personal preference. If you haven't used Path Finder yet, you should give it a try.</p>

<p>If you are sticking with Finder, there are some tricks that can make it better. Please leave a comment if you have any suggestions. </p>

<ul>
<li>Rename: type "enter" in any selected file name </li>
<li>Create New Folder: Command + Shift + N (New)</li>
<li>Connect to Server: <span class="caps">AFP</span>:// for mac, <span class="caps">SMB</span>:// for windows, or even <span class="caps">FTP</span>:// . Shortcut: Command + K</li>
<li>Go to the Folder: Command + Shift + G (GO)</li>
<li>Command + 1~4 to switch view</li>
<li>Command + N to open a new Finder window</li>
<li>Command + I to get the information on a Folder or File.</li>
</ul>

<h2><span class="caps">FTP</span></h2>

<p>You <strong>need</strong> a <span class="caps">FTP GUI </span>client. Why? There is no reason not to get it and plenty of reasons why you should have one. <br />
<a href="http://filezilla-project.org/">Filezilla</a> I don't recommend it. It is a cross platform <span class="caps">FTP </span>software, but visually it's not Mac-styled. <br />
<a href="http://cyberduck.ch/">Cyberduck</a> My #1 choice of free <span class="caps">FTP </span>client. Clean and fast, with support for <span class="caps">FTP, SFTP,</span> WebDAV, and cloud storage like Google and Amazon Cloud. <br />
<a href="http://panic.com/transmit/">Transmit</a> Commercial software, costs $34. Since I don't have that much requirement for <span class="caps">FTP </span>transmissions. I haven't got a copy for it.</p>

<h2>Automator</h2>

<p>Automator can automate lots of things in Mac and you don't need to remember a bunch of command and type them in the folder. There is one time, our client send us assets with ipad2 and ipad3 suffix in the filename. We need to rename them all to normal name (no suffix) and retina version (with @2x suffix). With Automator, it is all done in just a few clicks. </p>

<ul>
<li>First, launch Automator and create a new service. Name whatever you want.<br />
<span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/macguide/Automator.png?__SQUARESPACE_CACHEVERSION=1338246623137" alt=""/></span></span></li>
<li>Second, drag two items: "Get Folder Contents" and "Replace Text" into the work flow. Set other parameters as the image shown below:<br />
<span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/macguide/Rename__.png?__SQUARESPACE_CACHEVERSION=1338246641564" alt=""/></span></span></li>
<li>Save and use it. Select any file or folder in Finder. Choose Finder -&gt; Service -&gt; Rename__(Script name you typed). A window will popup for renaming. </li>
</ul>

<h2>Optimization</h2>

<p>After a using Mac for a while, it becomes slower and slower. There are something we can do to make it faster. I will explain each one of them so you can know how to speed it up or bring it back if any error shows. </p>

<ol>
<li>First, run Disk Utility to perform a Repair Disk Permissions. It is harmless and can reduce some rare errors. I recommend that you run it once for a while. <br />
<span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/macguide/diskunity.png?__SQUARESPACE_CACHEVERSION=1338246662590" alt=""/></span></span></li>
<li>Clean history, system cache and application caches using <a href="http://www.piriform.com/ccleaner/download">CCleaner</a> or <a href="http://itunes.apple.com/us/app/iboostup/id484829041?mt=12">iBoostUp</a>. You can also use <a href="http://www.syniumsoftware.com/cleanapp/">CleanApp</a> to uninstall an app and remove it's related files. It is an important step to rejuvenate your Mac. </li>
<li>Double check if you are using <span class="caps">NTFS </span>driver like <a href="http://www.paragon-software.com/home/ntfs-mac/">Paragon <span class="caps">NTFS</span></a>, turn it off if you are not using it. The reason for it is that if you enable spotlight(you should), it will try to create the index in your <span class="caps">NTFS </span>partition, which will make the whole system extremely slow. If you have to use it for writing files to <span class="caps">NTFS </span>disk, disable spotlight indexing on <span class="caps">NTFS </span>disk. <br />
<span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/macguide/Spotlight.png?__SQUARESPACE_CACHEVERSION=1338246948333" alt=""/></span></span></li>
<li>Disable unused items in Login Items window. There are lots of things you don't need to start it every time you boot your sweet Mac. They are just slowing it more and more. Disable them, leave your favorites only!. <br />
<span class="full-image-block ssNonEditable"><span><img src="http://www.nanaimostudio.com/storage/macguide/Users.png?__SQUARESPACE_CACHEVERSION=1338246671894" alt=""/></span></span></li>
<li>Validate Fonts, some broken or duplicated fonts can also cause problem of slowing the dear Mac machine. Open Font Book App, select all fonts, and then File -&gt; Validate Fonts. Fix error if any shows on Font Book. </li>
<li>Turn off Speech Recognition, and Internet Sharing if you don't use them. You can also turn off Universal Access and Bluetooth, but "Universal Access" is used by Accessior which is a great software I will introduce later, and my keyboard and mouse are using Bluetooth. I left these two on. </li>
<li>Clean out your unused widget. </li>
<li>Use <a href="http://www.titanium.free.fr/download.php">Onyx</a> to do maintenance. The official site is <a href="http://www.onyxmac.com/">www.onyxmac.com</a>. Be careful to click the right download link which is <a href="http://www.titanium.free.fr/download.php">http://www.titanium.free.fr/download.php</a> Be careful of doing anything on it.</li>
<li>Additionally, you can clean up Launch Service. The files can be found at </li>
</ol>

<pre><code>~/Library/LaunchAgents
/Library/LaunchAgents
/Library/LaunchDaemons</code></pre>

<p>After you install Adobe Master Suite, Autodesk Maya, or TeamViewer, they run some background services on your future login (annoying isn't it?). Just clean the files in the three folders above to disable them. Be sure to backup these files first. More explanation:</p>

<p>Launch daemons can run without a user logged in and it cannot display information using any <span class="caps">GUI.</span> The configuration plist files for launch daemons are stored in <strong>/System/Library/LaunchDaemons</strong> folder (for things provided by Apple) and <strong>/Library/LaunchDaemons</strong> (for everything else)</p>

<p>Launch agents run on behalf of a user and therefore need the user to be logged in to run. launch agents can display information through the window server. As with launch daemons, launch agent configuration plist files are stored in the <strong>/System/Library/LaunchAgents</strong> and <strong>/Library/LaunchAgents</strong>. User launch agents are installed in the <strong>~/Library/LaunchAgents</strong> folder.</p>

<h2>Conclusion</h2>

<p>So that wraps up a few of the best and most useful tools we use as Apple developers. Hope this will make you a more productive Apple developer! What other tools do you use? Comment below so we can compare. Love the list of tools we have introduced? Well then share the developer love on <a href="http://www.twitter.com/nanaimostudio">Twitter</a> or <a href="http://www.facebook.com/nanaimostudio">Facebook</a>!</p>
]]></content></entry></feed>