<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Metal Fish Eggs &#187; Tutorials</title>
	<atom:link href="http://blog.zincroe.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zincroe.com</link>
	<description>Ramblings from the team at zinc Roe</description>
	<lastBuildDate>Fri, 23 Jul 2010 20:45:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mirrored Video Object in Flash</title>
		<link>http://blog.zincroe.com/2010/07/mirrored-video-object-in-flash/</link>
		<comments>http://blog.zincroe.com/2010/07/mirrored-video-object-in-flash/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 20:29:34 +0000</pubDate>
		<dc:creator>Carlo</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[mirror]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://blog.zincroe.com/?p=674</guid>
		<description><![CDATA[When using the webcam in your flash applications, it can be handy to flip the video object so it acts like a mirror. Many of the flash webcam demos out there does exactly this, usually by setting the scaleX property&#8230;]]></description>
			<content:encoded><![CDATA[<p>When using the webcam in your flash applications, it can be handy to flip the video object so it acts like a mirror. Many of the flash webcam demos out there does exactly this, usually by setting the scaleX property of the video object to -1. Unfortunately, because the registration point of the video object is set on the top left corner, setting the scaleX property to a negative value moves the display object like flipping a page in a book from right to left.</p>
<div id="attachment_675" class="wp-caption aligncenter" style="width: 478px"><a href="http://blog.zincroe.com/wp-content/uploads/2010/07/reg_point.jpg"><img src="http://blog.zincroe.com/wp-content/uploads/2010/07/reg_point.jpg" alt="Setting scaleX to -1 on a display object" title="Setting scaleX to -1 on a display object" width="468" height="257" class="size-full wp-image-675" /></a><p class="wp-caption-text">Setting scaleX to -1 on a display object</p></div>
<p>Of course, you can easily place the video object back to where it was by compensating for the flip and adding the video object&#8217;s width to it&#8217;s current x value. While this solution works for most applications, there is one annoying thing about this method. If you ever want to move the video object around the stage or play with it&#8217;s scaleX value, there&#8217;s going to be a lot of compensating going on and it can get messy quick depending on the complexity of your application.</p>
<p>So to make it easier, here&#8217;s a class that extends the Video object and adds a &#8220;flipped&#8221; property. I don&#8217;t think I need to explain what the property does, but the class overrides the x and scaleX properties of Video so that it takes care of all the positioning when flipping the display object. Check out the demo [webcam required]:</p>
<p><object id="MirrorDemo" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="align" value="middle" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#cccccc" /><param name="src" value="http://blog.zincroe.com/wp-content/uploads/2010/07/HardwareDetection.swf" /><param name="name" value="MirrorDemo" /><param name="allowfullscreen" value="false" /><embed id="MirrorDemo" type="application/x-shockwave-flash" width="550" height="400" src="http://blog.zincroe.com/wp-content/uploads/2010/07/HardwareDetection.swf" name="MirrorDemo" bgcolor="#cccccc" quality="high" allowfullscreen="false" allowscriptaccess="sameDomain" align="middle"></embed></object></p>
<p>Even when flipped, the x property always references the left side of the video object and the scaleX remains the same. Here&#8217;s the source: <a href='http://blog.zincroe.com/wp-content/uploads/2010/07/MirrorDemo.zip'>MirrorDemo.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zincroe.com/2010/07/mirrored-video-object-in-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Motion &amp; Activity Tracking in Flash</title>
		<link>http://blog.zincroe.com/2009/07/motion-activity-tracking-in-flash/</link>
		<comments>http://blog.zincroe.com/2009/07/motion-activity-tracking-in-flash/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 15:28:08 +0000</pubDate>
		<dc:creator>Carlo</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Show and Tell]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.zincroe.com/?p=282</guid>
		<description><![CDATA[With the introduction of <em>FLARToolkit</em> and other means of tracking user input through a webcam in flash, I recently had a chance to read up on some of the other ways we can interact with flash applications using a webcam.
<strong>Camera.activityLevel</strong>
The&#8230;]]></description>
			<content:encoded><![CDATA[<p>With the introduction of <em>FLARToolkit</em> and other means of tracking user input through a webcam in flash, I recently had a chance to read up on some of the other ways we can interact with flash applications using a webcam.</p>
<p><strong>Camera.activityLevel</strong></p>
<p>The most basic way to detect activity through a webcam in flash is by accessing the Camera object&#8217;s <em>activityLevel</em> property. This returns a number from 0 to 100, depending on how much activity is going on. While useful in simple applications, this doesn&#8217;t give us a way to check for specific gestures or a way to check a specific section of the video for activity.</p>
<p><strong>BitmapData.getPixel()</strong></p>
<p>A popular way to detect motion is by using the <em>BitmapData</em> object in flash. By taking &#8220;snapshots&#8221; of the video coming in from the webcam constantly (using either <em>Event.ENTER_FRAME</em>, or the <em>Timer</em> object), we end up with frames that we can compare by looping through each pixel and checking to see which has changed. This technique is useful for checking which areas of the video has activity. We can use it to interact with buttons or other display objects by simply waving our hand over it. Though it can be very intensive (specially when working with video that has large dimensions), it is one of the best and most reliable way to detect motion in flash.</p>
<p><strong>Augmented Reality &amp; Marker Tracking</strong></p>
<p>As mentioned earlier, another option is to use <a title="FLARToolkit" href="http://www.libspark.org/wiki/saqoosha/FLARToolKit/en" target="_blank">saqoosha&#8217;s FLARToolkit</a>. If you haven&#8217;t played with it before, you should definitely check it out&#8230;after reading my blog post to the end, of course. From what I understand (and correct me if I&#8217;m wrong), this neat library also uses the BitmapData object to take stills of the video from the webcam. It then manipulates the bitmaps in order to detect and extract the position of a marker in 3D space. You can then use flash 3D libraries like Papervision to apply those coordinates to a 3D object and display it on top of the marker as if it&#8217;s a physical object. This method requires the user to print out a specific symbol and display it in front of a webcam. The wicked thing about FLARToolkit is that it doesn&#8217;t restrict you to using just Papervision, you can use Away3D or no 3D at all!</p>
<p>Though it comes packaged with Papervision and Away3D, with a bit of &#8220;code spelunking&#8221;, you can strip out the 3D stuff and gain access to the marker&#8217;s x,y, and z properties. By doing this, you end up with a basic marker tracking library which you can use for pretty much anything your nerdy heart desires. In my case, my nerdy heart and I created a very basic game where you have to catch falling apples using only simple vector MovieClips. Check it out below:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/1Rc1rBC9rd4&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="340" src="http://www.youtube.com/v/1Rc1rBC9rd4&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a href="http://blog.zincroe.com/wp-content/uploads/2009/07/FallingApples.zip">Download Source</a></p>
<p><strong>Moving MovieClips with your hand (or other limbs) using the webcam</strong></p>
<p>Now after playing with the BitmapData motion detection and the FLARToolkit, I went on a mission. A mission to find/figure out a way to interact with display objects on the stage using the webcam, BUT without using markers. After a bit of searching, I was able to find this <a title="Bubble Demo" href="http://www.youtube.com/watch?v=u8tGiV6M2qY&amp;feature=related" target="_blank">demo on youtube</a> which is close to what I want but with more control over the display object&#8217;s reaction.</p>
<p>Using what I&#8217;ve learned, and some inspiration from the youtube demo, I threw a quick example together as a learning exercise for myself. By checking for activity where our &#8220;box&#8221; movieclip is located, we can check which side has the most activity and move the box in the proper direction as if it&#8217;s a physical box you can push around. Though it&#8217;s not perfect and could DEFINITELY use some more code optimization, I was very satisfied with the result.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/mBNhxPyJs6I&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="340" src="http://www.youtube.com/v/mBNhxPyJs6I&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a href="http://blog.zincroe.com/wp-content/uploads/2009/07/MotionDetect.zip">Download Source</a></p>
<p><strong>AS3 Real-Time Face Detection</strong></p>
<p>Another technique worth mentioning is face detection in flash. Here&#8217;s a snippet taken from <a title="AS3 Face Detection" href="http://www.quasimondo.com/archives/000687.php" target="_blank">Mario Klingemann&#8217;s blog</a> about the subject:</p>
<blockquote><p><em>&#8220;Yesterday Seb-Lee Delisle pointed us via Twitter to this great example of a Flash based real-time face detection. It turns out that already more than half a year ago Ohtsuka Masakazu had been porting the face detection part of OpenCV to AS3 and added the source code to the Spark project &#8211; which is like a Actionscript candy box full of surprises.&#8221;</em></p></blockquote>
<p>He then explains how it works and how to optimize it, it&#8217;s a good read for those interested in the subject.</p>
<p>So there you have it, we went from detecting basic general webcam activity in flash to complex face detection algorithms. Big kudos to the folks mentioned in this post as they&#8217;ve put in many hours coding in order for the rest of us to create awesome and engaging content with ease.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zincroe.com/2009/07/motion-activity-tracking-in-flash/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Project Organization and Coding Conventions for iPhone Games</title>
		<link>http://blog.zincroe.com/2009/05/project-organization-and-coding-conventions-for-iphone-games/</link>
		<comments>http://blog.zincroe.com/2009/05/project-organization-and-coding-conventions-for-iphone-games/#comments</comments>
		<pubDate>Thu, 07 May 2009 19:23:48 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.zincroe.com/?p=179</guid>
		<description><![CDATA[Now that we&#8217;re knee deep in iPhone game development, we&#8217;re working with a number of different outside developers. Since everyone involved is pretty new to Objective-C, XCode and iPhone development, project organization and coding conventions in our projects have been&#8230;]]></description>
			<content:encoded><![CDATA[<p>Now that we&#8217;re knee deep in iPhone game development, we&#8217;re working with a number of different outside developers. Since everyone involved is pretty new to Objective-C, XCode and iPhone development, project organization and coding conventions in our projects have been all over the map. To improve the quality of our projects and make them easier to maintain and update, here&#8217;s a list of things to keep in mind when developing casual games for the iPhone. Most of them are common sense, but going back to basics every now and then never hurts.</p>
<ul class="tutorial">
<li>Remember that somebody else (who may not know all the ins and outs of XCode) will be working on the project with you. Take the time to keep things neat and organized. Create a Classes folder with all your source code and a Resources folder with nib files, images, sounds, etc. Keep the organization of the project and the organization of the files on disk as close as possible, it&#8217;s less confusing for everyone. Give all of your files consistent descriptive names. Delete files that aren&#8217;t being used anymore (<em>Tip:</em> Make bundles for any resources that don&#8217;t need to be compiled, like images and sounds. XCode doesn&#8217;t keep track of the contents of bundle files, which means when you add/remove/rename files in the bundle XCode will automatically see the changes so you don&#8217;t have to remember to add and remove them from the project). Simple stuff, but it makes a big difference.</li>
<li>Pushing updates to the App Store is a proven way of improving a game&#8217;s visibility, so make sure the project and the code are easy to update. Remember to slow down and do things well.</li>
<li>Use Foundation and UIKit classes wherever possible — it helps keep user interface elements consistent and it&#8217;s easy for another developer to quickly see what&#8217;s going on and make changes without learning another 3rd party framework. For example, use a UIView with UIButtons for game screens. The exception to the rule here is the game engine itself, where the benefits of using OpenGL or other open source code are worth the trouble.</li>
<li>Use Interface Builder wherever possible — this goes hand-in-hand with the last point. Using UIKit classes and Interface Builder makes it easy to adjust the layout of screens, labels for buttons, etc. without hunting through the code. Remember, the person making the adjustments may not be a programmer.</li>
<li>Use UILabels for interface text, rather than embedding text in images. Keeping text out of images makes the project much easier to update and localize. Using native text for everything also helps keep things consistent visually – your high score screen is going to need dynamic text and the app will look better if it matches everything else.</li>
<li>Memory management is very high priority on the iPhone. Use as little memory as possible. Don&#8217;t load things into memory until you need them. Release things from memory when you&#8217;re done with them. For example, rather than loading all of a games screens when the app launches and keeping them in memory for the life of the app, load each screen when it&#8217;s going to be shown and release it from memory after it&#8217;s hidden.</li>
<li>Test the app regularly in Instruments during development to find memory leaks and avoid wasting memory:
<ul>
<li>Check using Leaks — This will help you find good, old-fashioned memory leaks.</li>
<li>Check using Object Allocations — An object in memory may not technically be a leak, but if it doesn&#8217;t need to be there it&#8217;s wasted memory. When you&#8217;re playing the game, are any of the objects associated with the other screens in memory? When you&#8217;re showing the game over screen, are any of the objects associated with the game engine in memory?</li>
<li>Check using Memory Monitor — Apple doesn&#8217;t specify a hard limit on the amount of memory an app can use, but the general consensus is that 15Mb to 20Mb is fairly safe. If your app is using 25Mb of memory you should be concerned. If your app is using 45Mb of memory you have a very big problem.</li>
<li>Check OpenGL Texture Memory — OpenGL on the iPhone has a soft limit of 24Mb for all textures. If you go above the limit, there&#8217;s a massive performance hit. See: <a href="http://blog.zincroe.com/2009/04/how-to-check-iphone-texture-memory-usage-with-instruments/">How To Check iPhone Texture Memory Usage With Instruments</a></li>
</ul>
</li>
<li>Follow standard Objective-C naming conventions. They&#8217;re different from other languages, so take the time to read up on them. See: <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html">Coding Guidelines for Cocoa</a>, <a href="http://www.cocoadevcentral.com/articles/000082.php">Cocoa Style for Objective-C: Part I</a>, <a href="http://www.cocoadevcentral.com/articles/000083.php">Cocoa Style for Objective-C: Part II</a></li>
<li>Put the <code>dealloc</code> method at the top of the <code>@implementation</code> block for every class you write. <code>dealloc</code> is the most important method in every class, so show it some love.</li>
<li>Use accessor methods for <strong>everything</strong> — it&#8217;s the best way to avoid simple memory management bugs. Use accessor methods within classes, too. You can define private accessor methods in a category at the top of your implementation file. You can redefine a readonly property in the public interface as a readwrite property in the private category.</li>
<li>Mark properties as <code>nonatomic</code> unless you have a good reason not to.</li>
<li>Use square bracket syntax (i.e. <code>[self foo]</code>, <code>[self setFoo:@"bar"]</code>) instead of dot syntax (i.e. <code>self.foo</code>, <code>self.foo = @"bar"</code>) for accessing properties. Using one syntax keeps your code consistent, and makes it easier to see where you&#8217;re accessing a property of an Objective-C object as opposed to a member of a C struct or C++ class (which use dot notation).</li>
<li>Avoid subclassing UIViews. Build the view hierarchy in Interface Builder and put your logic in a UIViewController. If you have a lot of UIView subclasses, you should be concerned.</li>
<li>Remember to mark properties as <code>IBOutlet</code>s and methods as <code>IBAction</code>s wherever it makes sense.</li>
<li>Organize related methods and properties into groups in the source code (i.e. the UIViewController subclass for a game screen might have groups like button properties, action methods and overridden UIViewController methods). Mark the groups in both the header and the implementation using <code>#pragma mark <em>Label</em></code>. Organize methods within a group alphabetically. You&#8217;ll spend a bit of time organizing things and a lot less time looking for things.</li>
<li>Use <code>NSAssert()</code> liberally. If you intentionally stop the app when something unexpected occurs, it&#8217;s easier to find where the problem started and fix it. It takes a bit of time to write the assertions, but I guarantee it takes less time than tracking down a bug later on.</li>
</ul>
<p>The list above is by no means definitive, but it covers the basics. Let me know if I&#8217;ve left out anything obvious, or if there&#8217;s something that rubs you the wrong way. I&#8217;m always happy to learn a better way to do something.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zincroe.com/2009/05/project-organization-and-coding-conventions-for-iphone-games/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How To Add Box2D To An iPhone XCode Project</title>
		<link>http://blog.zincroe.com/2009/05/how-to-add-box2d-to-an-iphone-xcode-project/</link>
		<comments>http://blog.zincroe.com/2009/05/how-to-add-box2d-to-an-iphone-xcode-project/#comments</comments>
		<pubDate>Thu, 07 May 2009 15:06:39 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.zincroe.com/?p=153</guid>
		<description><![CDATA[Using Box2D is a great way to add physics to a 2D iPhone game. Since Box2D is written in C++ rather than Objective-C, adding it to your XCode project and getting it to build cleanly can be a bit tricky.&#8230;]]></description>
			<content:encoded><![CDATA[<p>Using Box2D is a great way to add physics to a 2D iPhone game. Since Box2D is written in C++ rather than Objective-C, adding it to your XCode project and getting it to build cleanly can be a bit tricky. If you just want to get aquainted with Box2D, there is an sample XCode project in the Box2D svn repository that includes the Box2D testbed and basic debug drawing support for the iPhone. Once you get past some quick experiments, you&#8217;ll probably want to add Box2D to a clean XCode project with a minimum of cruft. It&#8217;s not tough, but there are a couple of gotchas along the way. Below are instructions for adding Box2D to a new iPhone XCode project and getting that project to build cleanly on a device (note: the project doesn&#8217;t actually do anything, that&#8217;s where you come in&#8230;).</p>
<p>The instructions below assume you&#8217;re a registered iPhone developer and have:</p>
<ul>
<li>Mac OS X 10.5</li>
<li>XCode 3.1.2</li>
<li>iPhone SDK 2.2.1</li>
<li>Box2D 2.0.2</li>
<li>A valid app id and development provisioning profile that you can use to build the project for a device.</li>
</ul>
<p>So, for my future reference and yours&#8230;.</p>
<ol class="tutorial">
<li>Create a new XCode project. I&#8217;m creating a <em>View-Based Application</em> called <em>MyGame </em> on my desktop.
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/01.png"><img class="alignnone size-medium wp-image-154" title="01" src="http://blog.zincroe.com/wp-content/uploads/2009/05/01-450x326.png" alt="01" width="450" height="326" /></a></p>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/02.png"><img class="alignnone size-medium wp-image-155" title="02" src="http://blog.zincroe.com/wp-content/uploads/2009/05/02-450x348.png" alt="02" width="450" height="348" /></a></p>
</li>
<li>
	  Open the terminal and export Box2D 2.0.2 from the Box2D svn repository into your project folder:<br />
	  <code>svn export https://box2d.svn.sourceforge.net/svnroot/box2d/tags/Box2D-2.0.2 ~/Desktop/MyGame/Box2D-2.0.2</code>
  </li>
<li>Right click on <em>MyGame</em> under <em>Groups &amp; Files</em> and choose <em>Add &gt; Existing Files&#8230;</em>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/04.png"><img class="alignnone size-medium wp-image-156" title="04" src="http://blog.zincroe.com/wp-content/uploads/2009/05/04-450x319.png" alt="04" width="450" height="319" /></a></p>
</li>
<li>Browse to the your project directory, select the Box2D-2.0.2 folder and click <em>Add</em>.
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/05.png"><img class="alignnone size-medium wp-image-157" title="05" src="http://blog.zincroe.com/wp-content/uploads/2009/05/05-450x364.png" alt="05" width="450" height="364" /></a></p>
</li>
<li>Make sure the <em>Copy items into destination group&#8217;s folder</em> checkbox is unchecked and click <em>Add</em>.
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/06.png"><img class="alignnone size-full wp-image-158" title="06" src="http://blog.zincroe.com/wp-content/uploads/2009/05/06.png" alt="06" width="400" height="374" /></a></p>
</li>
<li>Expand the <em>Box2D-2.0.2</em> group and delete everything except the <em>Include</em> and <em>Source</em> groups. Whether you move the files to the trash or just delete the references is up to you.
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/07a.png"><img class="alignnone size-medium wp-image-159" title="07a" src="http://blog.zincroe.com/wp-content/uploads/2009/05/07a-450x319.png" alt="07a" width="450" height="319" /></a></p>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/07c.png"><img class="alignnone size-medium wp-image-161" title="07c" src="http://blog.zincroe.com/wp-content/uploads/2009/05/07c-450x319.png" alt="07c" width="450" height="319" /></a></p>
</li>
<li>Expand the <em>Source</em> group and delete the Makefile.
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/08a.png"><img class="alignnone size-medium wp-image-162" title="08a" src="http://blog.zincroe.com/wp-content/uploads/2009/05/08a-450x319.png" alt="08a" width="450" height="319" /></a></p>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/08b.png"><img class="alignnone size-medium wp-image-163" title="08b" src="http://blog.zincroe.com/wp-content/uploads/2009/05/08b-450x319.png" alt="08b" width="450" height="319" /></a></p>
</li>
<li>If you haven&#8217;t already, set the app id (in <em>Resources/Info.plist</em>) and the <em>Code Signing Identity</em> in the project build settings (in <em>Project &gt; Edit Project Settings &gt; Build</em>). Make sure you have <em>Device 2.2.1</em> and <em>Debug</em> selected in the menu at the top left corner of XCode (anyone know what this menu is called?). Finally, build the project (<em>Command-B</em>).</li>
<li>Open up the build results (<em>Command-Shift-B</em>), and you&#8217;ll see a whole bunch of errors, along the lines of:
<p><code>error: 'finite' was not delcared in this scope</code></p>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/09.png"><img class="alignnone size-medium wp-image-164" title="09" src="http://blog.zincroe.com/wp-content/uploads/2009/05/09-450x250.png" alt="09" width="450" height="250" /></a></p>
</li>
<li>Open the project build settings (<em>Project &gt; Edit Project Settings &gt; Build</em>) and find the <em>Other C Flags</em> setting. Add the following flag, which tells Box2D that it&#8217;s being compiled for the iPhone so that it knows where to find the standard C++ libraries.
<p><code>-DTARGET_OS_IPHONE</code></p>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/10.png"><img class="alignnone size-medium wp-image-165" title="10" src="http://blog.zincroe.com/wp-content/uploads/2009/05/10-412x450.png" alt="10" width="412" height="450" /></a></p>
</li>
<li>Build the project again (<em>Command-B</em>). It will build cleanly, but we&#8217;re not quite out of the woods yet.</li>
<li>Open <em>MyGameViewController.m</em> and add the following line at the top of the file:
<p><code>#import "Box2D.h"</code></p>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/11.png"><img class="alignnone size-medium wp-image-166" title="11" src="http://blog.zincroe.com/wp-content/uploads/2009/05/11-450x319.png" alt="11" width="450" height="319" /></a></p>
</li>
<li>Build the project again (<em>Command-B</em>). Yay, more errors:
<p><code>error: initializer element is not constant</code></p>
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/12.png"><img class="alignnone size-medium wp-image-167" title="12" src="http://blog.zincroe.com/wp-content/uploads/2009/05/12-450x250.png" alt="12" width="450" height="250" /></a></p>
</li>
<li>Select all of the <code>.m</code> files in your project (yes, all of them).
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/13a.png"><img class="alignnone size-medium wp-image-168" title="13a" src="http://blog.zincroe.com/wp-content/uploads/2009/05/13a-450x319.png" alt="13a" width="450" height="319" /></a></p>
</li>
<li>Click the <em>Info</em> button in the toolbar, go to the <em>General</em> tab and find the <em>File Type</em> dropdown.
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/13b.png"><img class="alignnone size-medium wp-image-169" title="13b" src="http://blog.zincroe.com/wp-content/uploads/2009/05/13b-412x450.png" alt="13b" width="412" height="450" /></a></p>
</li>
<li>Change the filetype from <code>sourcecode.c.objc</code> to <code>sourcecode.cpp.objcpp</code>. This tells XCode to compile the files as Objective-C++ (mixed Objective-C and C++ code) instead of plain Objective-C code.
<p class="screenshot"><a href="http://blog.zincroe.com/wp-content/uploads/2009/05/13c.png"><img class="alignnone size-medium wp-image-170" title="13c" src="http://blog.zincroe.com/wp-content/uploads/2009/05/13c-412x450.png" alt="13c" width="412" height="450" /></a></p>
</li>
<li>Build the project again (<em>Command-B</em>). That&#8217;s it!</li>
</ol>
<p>So there you go, you&#8217;re ready to start using Box2D on the iPhone. Just remember to change the file type from <code>sourcecode.c.objc</code> to <code>sourcecode.cpp.objcpp</code> for any <code>.m</code> files you add to the project.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zincroe.com/2009/05/how-to-add-box2d-to-an-iphone-xcode-project/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to check iPhone texture memory usage with Instruments</title>
		<link>http://blog.zincroe.com/2009/04/how-to-check-iphone-texture-memory-usage-with-instruments/</link>
		<comments>http://blog.zincroe.com/2009/04/how-to-check-iphone-texture-memory-usage-with-instruments/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 15:19:16 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.zincroe.com/?p=124</guid>
		<description><![CDATA[
When developing iPhone games, one of the biggest performance optimizations you can make is to use OpenGL ES for rendering (instead of CoreGraphics or UIKit). For a 2D game like Arctic Shuffle, this means loading all of the animation into&#8230;]]></description>
			<content:encoded><![CDATA[<div>
<p>When developing iPhone games, one of the biggest performance optimizations you can make is to use OpenGL ES for rendering (instead of CoreGraphics or UIKit). For a 2D game like Arctic Shuffle, this means loading all of the animation into Open GL as textures, and drawing them onto simple rectangular shapes.</p>
<p>There are two caveats to this approach. First, disk access on the device is dirt slow, so you can forget about loading textures on the fly – all of the textures need to be loaded before gameplay begins. Second, OpenGL ES on the iPhone has a texture memory limit of 24MB. If you try to load more than 24MB of textures (including any buffers, like the framebuffer), the device has to start swapping them in and out of memory, and you go over a performance cliff, so to speak.</p>
<p>With that in mind, it&#8217;s very helpful to know how much texture memory is being used by your game – this is where Instruments comes in (the instructions below assume that your device is plugged into your development machine and you already have a working debug build of your game on the device).</p>
<p>1. Open Instruments (/Developer/Applications/Instruments.app) and choose the &#8220;Blank&#8221; template.</p>
<p><a href="http://blog.zincroe.com/wp-content/uploads/2009/04/step1.png"><img class="alignnone size-medium wp-image-125" style="border: 1px solid black;" title="Step 1" src="http://blog.zincroe.com/wp-content/uploads/2009/04/step1-450x329.png" alt="Step 1" width="450" height="329" /></a></p>
<p>2. In the bottom-left corner of instruments, click on the gear icon, then choose <em>Add Instrument &gt; Memory Monitory</em>. Click the gear icon again and choose <em>Add Instrument &gt; OpenGL ES</em>.</p>
<p><a href="http://blog.zincroe.com/wp-content/uploads/2009/04/step2.png"><img class="alignnone size-full wp-image-126" style="border: 1px solid black;" title="Step 2" src="http://blog.zincroe.com/wp-content/uploads/2009/04/step2.png" alt="Step 2" width="438" height="280" /></a></p>
<p>3. Click on the OpenGL ES instrument&#8217;s <em>info</em> icon, and make sure that <em>GARTResident Object Size</em> is checked.</p>
<p><a href="http://blog.zincroe.com/wp-content/uploads/2009/04/step3.png"><img class="alignnone size-medium wp-image-127" style="border: 1px solid black;" title="Step 3" src="http://blog.zincroe.com/wp-content/uploads/2009/04/step3-396x450.png" alt="Step 3" width="396" height="450" /></a></p>
<p>4. Choose the device and application you wan to check. My device is named <em>Barracuda</em> and the application is ArcticShuffle2.</p>
<p><a href="http://blog.zincroe.com/wp-content/uploads/2009/04/step4.png"><img class="alignnone size-medium wp-image-128" style="border: 1px solid black;" title="Step 4" src="http://blog.zincroe.com/wp-content/uploads/2009/04/step4-450x252.png" alt="Step 4" width="450" height="252" /></a></p>
<p>5. Click the record button. This will launch the application on the device, and start monitoring it&#8217;s memory and OpenGL ES usage. The GARTResident Object Size column shows the amout of texture memory used, in bytes. Divide that by 1024 (i.e. amount / 1024 / 1024) to convert the number to megabytes. Notice how the <em>Frames Per Second</em> drops dramatically while the textures are loading.</p>
<p><a href="http://blog.zincroe.com/wp-content/uploads/2009/04/step5.png"><img class="alignnone size-medium wp-image-129" style="border: 1px solid black;" title="Step 5" src="http://blog.zincroe.com/wp-content/uploads/2009/04/step5-421x450.png" alt="Step 5" width="421" height="450" /></a></p>
<p>Happy Optimizing!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zincroe.com/2009/04/how-to-check-iphone-texture-memory-usage-with-instruments/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
