<?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>Buzzard Software, LLC. &#187; Engineering</title>
	<atom:link href="http://www.buzzardsoft.com/category/engineering/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.buzzardsoft.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 16:02:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Cocoa: Finding the window that your sheet is attached to</title>
		<link>http://www.buzzardsoft.com/2012/05/17/cocoa-finding-the-window-that-your-sheet-is-attached-to/</link>
		<comments>http://www.buzzardsoft.com/2012/05/17/cocoa-finding-the-window-that-your-sheet-is-attached-to/#comments</comments>
		<pubDate>Fri, 18 May 2012 03:49:26 +0000</pubDate>
		<dc:creator>buzzard</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[NSWindow]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sheets]]></category>

		<guid isPermaLink="false">http://www.buzzardsoft.com/?p=165</guid>
		<description><![CDATA[I recently had a situation where I needed to chain together two modal sheets off the same window. When the first sheet was presented, I obviously had the NSWindow object for the window I wanted to attach to. Since my &#8230; <a href="http://www.buzzardsoft.com/2012/05/17/cocoa-finding-the-window-that-your-sheet-is-attached-to/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently had a situation where I needed to chain together two modal sheets off the same window. When the first sheet was presented, I obviously had the <code>NSWindow</code> object for the window I wanted to attach to. Since my sheet had its own controller object, I could have simply stored this <code>NSWindow</code> object and used it later for the next sheet.</p>
<p>However, I decided &#8211; largely as a matter of taste &#8211; that I&#8217;d rather figure out the sheet&#8217;s &#8220;parent&#8221; window programmatically in the <code>didEndSelector</code> when the first sheet is dismissed. That way I don&#8217;t need to store the parent window anywhere in my controller.</p>
<p><span id="more-165"></span></p>
<p>To do so, you can walk the window list and ask each window for its <code>attachedSheet</code>, comparing against the sheet window that is being dismissed. I&#8217;ve wrapped this in a category on <code>NSWindow</code>, shown below.</p>
<div style="font-size: 11px">
<pre class="brush: objc; highlight: [20,21,22,25,28]; title: ; notranslate">
/*
    NSWindow+BSSheetParent.h
 */
#import &lt;Cocoa/Cocoa.h&gt;

@interface NSWindow (BSSheetParent)
- (NSWindow*) sheetParent: (NSWindow*) sheetWindow;
@end

/*
    NSWindow+BSSheetParent.m
 */
#import &quot;NSWindow+SheetParent.h&quot;

@implementation NSWindow (BSSheetParent)
- (NSWindow*) sheetParent
{
    NSWindow * sheetParent = nil;

    if(self.isSheet)
    {
        NSArray * allWindows = [NSApp windows];
        for(NSWindow * aWindow in allWindows)
        {
            if(aWindow == self)
                continue;

            if(aWindow.attachedSheet == self)
            {
                sheetParent = aWindow;
                break;
            }
        }
    }

    return sheetParent;
}
@end
</pre>
</div>
<p>Lines of note:</p>
<ul>
<li><strong>Line 20 </strong>- If the argument window isn&#8217;t a sheet, then don&#8217;t bother searching.  Its sheet parent will be nil</li>
<li><strong>Line 21</strong> &#8211; get all of the windows from the app controller</li>
<li><strong>Line 22</strong> &#8211; iterate through all the windows</li>
<li><strong>Line 25</strong> &#8211; if we find the argument window, just skip it. It can&#8217;t be the sheet parent of itself</li>
<li><strong>Line 28</strong> &#8211; If the current window&#8217;s attached sheet is the argument window, then we&#8217;ve found the sheet&#8217;s parent so we&#8217;re done</li>
</ul>
<p>Here&#8217;s how you might use it:</p>
<div style="font-size: 11px">
<pre class="brush: objc; highlight: [5,7,8,9,10,11,14,18,22,23,25,28,29,30,31,32,33,34,35,36,37]; title: ; notranslate">
/*
    MyController.m
 */
@implementation MyController
- (void) runMySheetAsModalForWindow: (NSWindow*) parentWindow
{
    [NSApp beginSheet: self.window
       modalForWindow: aWindow
        modalDelegate: self
       didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
          contextInfo: nil];
}

- (void)sheetDidEnd: (NSWindow*)sheet
         returnCode: (NSInteger)returnCode
        contextInfo: (void *)contextInfo
{
    BOOL needsToShowAlert = YES;  // figure out whether to warn the user

    if(needsToShowAlert)
    {
        NSWindow * sheetParent = [sheet sheetParent];
        NSAssert(sheetParent != nil, @&quot;Sheet apparently isn't hosted by another window&quot;);

        [sheet orderOut: self];

        // chain sheet alert...
        NSBeginAlertSheet(@&quot;Alert Title&quot;,
                          nil,            // default
                          @&quot;Cancel&quot;,
                          nil,
                          sheetParent,
                          self,
                          @selector(warningAlertDidEnd:returnCode:contextInfo:),
                          NULL,
                          NULL,
                          @&quot;Warning - do you really want to delete all your data?&quot;);
    }
}

/*...*/
@end
</pre>
</div>
<p>Here&#8217;s what this does:</p>
<ul>
<li><strong>Line 5</strong> &#8211; This is the entry point for running my sheet. It would be called from another window controller with the intent of having attaching the sheet to its window. If I were going to cache the sheet&#8217;s host window, this method is where I&#8217;d store it in an instance variable.</li>
<li><strong>Line 7</strong> &#8211; Run the sheet.  <code>self.window</code> is in an instance variable set up when the controller is initialized by the Nib (not shown)</li>
<li><strong>Line 14</strong> &#8211; This is what is called when the sheet is dismissed. Code to dismiss the sheet is not shown for brevity (use <code>[NSApp endSheet: returnCode])</code></li>
<li><strong>Line 18</strong> &#8211; You&#8217;d normally want to do something here to figure out whether to show another sheet (like a warning), like check the return code or check some values in your sheet controls.</li>
<li><strong>Line 22</strong> &#8211; Figure out the sheet&#8217;s host window, and assert if it isn&#8217;t found (it should be!).  This uses the category shown above to do the heavy lifting.</li>
<li><strong>Line 25</strong> &#8211; Get rid of the current sheet</li>
<li><strong>Line 28</strong> &#8211; Now show another sheet from the same originating window.</li>
</ul>
<p>Pretty straightforward, but also pretty useful in this circumstance.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buzzardsoft.com/2012/05/17/cocoa-finding-the-window-that-your-sheet-is-attached-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone game: converting to CALayer</title>
		<link>http://www.buzzardsoft.com/2009/11/05/iphone-game-converting-to-calayer/</link>
		<comments>http://www.buzzardsoft.com/2009/11/05/iphone-game-converting-to-calayer/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 04:54:29 +0000</pubDate>
		<dc:creator>buzzard</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.buzzardsoft.com/?p=41</guid>
		<description><![CDATA[In one of my previous posts I discussed my approach to starting development of a game. I&#8217;m still working on this, but I&#8217;ve come to the point where I may upgrade my drawing code a little bit. In my initial &#8230; <a href="http://www.buzzardsoft.com/2009/11/05/iphone-game-converting-to-calayer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In one of my <a href="http://blog.buzzardsoft.com/2009/09/17/iphone-game-prototype/">previous posts</a> I discussed my approach to starting development of a game. I&#8217;m still working on this, but I&#8217;ve come to the point where I may upgrade my drawing code a little bit.</p>
<p>In my initial development I was simply drawing into a UIView via its CGContext. Now I&#8217;m thinking about changing to drawing into CALayers. This gives me a few advantages. First, it lets me separate drawing a little bit more. I already have most of the drawing broken into separate methods in my view, but now I can set a layer for the score, and a layer for the objects (or even a layer <em>per</em> object). These aren&#8217;t too much of an advantage, but I think the biggest gain is that I can put a background image in a layer and then draw the rest of the items on top of it. I won&#8217;t need to redraw the background on the view for every frame of animation.</p>
<p>The second advantage is for some animations &#8211; I can just set them up and let them run. Take, for instance, an event like an explosion. I could create a few layers for some particles in the explosion, set them up on a path (maybe with some rotation), and then just let it run. I don&#8217;t have to add state tracking to animate these by hand with every frame.</p>
<p>I&#8217;ve only just started researching this, but I think this will work out nicely.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buzzardsoft.com/2009/11/05/iphone-game-converting-to-calayer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone touch accuracy</title>
		<link>http://www.buzzardsoft.com/2009/09/26/iphone-touch-accuracy/</link>
		<comments>http://www.buzzardsoft.com/2009/09/26/iphone-touch-accuracy/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 03:09:12 +0000</pubDate>
		<dc:creator>buzzard</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.buzzardsoft.com/?p=37</guid>
		<description><![CDATA[If you read my last post you know that I&#8217;m working on a game for iPhone.  As part of my experimentation, I ran across a small issue I thought I&#8217;d share. Part of my game play involves the user touching &#8230; <a href="http://www.buzzardsoft.com/2009/09/26/iphone-touch-accuracy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you read my <a href="/2009/09/17/iphone-game-prototype/">last post</a> you know that I&#8217;m working on a game for iPhone.  As part of my experimentation, I ran across a small issue I thought I&#8217;d share.</p>
<p><span id="more-37"></span></p>
<p>Part of my game play involves the user touching objects on the screen which can be fairly small.  In my light testing on my iPhone (along with some brief play testing done by my wife) it proved hard to hit within those objects.  I added some code to draw an &#8216;X&#8217; where the last touch occurred in order to track this.  Generally it seemed that the both of us were hitting down and to the right of the target area.  As we are both right-handed, I would guess that this it because our aim is guided largely by the position of our <em>fingertip </em>while the touch area is back from that at the <em>finger pad</em>.</p>
<p>The inaccuracy is not a surprise, I suppose.  Most standard user interface elements have a reasonably large target area and are at least static positionally, so this generally isn&#8217;t a problem in typical applications. In the height of game play, however, you don&#8217;t want to require touches to be too accurate, or you at least want the touches to match the position that the user expect the touch to occur. Otherwise, the player will become frustrated and will hate your game!</p>
<p>So, my solution? One of my considerations in my game design was to put my objects in a grid, rather than placing them in arbitrary locations on the screen.  As I implement this, I will start with registering a click on an object when the user clicks on the grid cell that contains it.  As it looks so far, the &#8216;X&#8217; I&#8217;m drawing for the last touch location appears to show touches in the intended grid cell.  That&#8217;s a good thing.  My one concern is that using the grid cell as a proxy for touching an object makes it too easy to touch small objects.  If that&#8217;s case, I&#8217;ll make touches require less accuracy by allowing a few pixels of slop outside the boundaries of the game object.</p>
<p>Has anybody else experience this in their game design? How did you solve it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buzzardsoft.com/2009/09/26/iphone-touch-accuracy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone game prototype</title>
		<link>http://www.buzzardsoft.com/2009/09/17/iphone-game-prototype/</link>
		<comments>http://www.buzzardsoft.com/2009/09/17/iphone-game-prototype/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 02:16:43 +0000</pubDate>
		<dc:creator>buzzard</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.buzzardsoft.com/?p=21</guid>
		<description><![CDATA[I&#8217;ve finally found some time to start working on an iPhone game that I&#8217;ve been thinking about writing. I won&#8217;t give out too many details of the game itself at this point, but I thought it might be interesting to &#8230; <a href="http://www.buzzardsoft.com/2009/09/17/iphone-game-prototype/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally found some time to start working on an iPhone game that I&#8217;ve been thinking about writing. I won&#8217;t give out too many details of the game itself at this point, but I thought it might be interesting to some of you if I share a few notes about my approach so far. I&#8217;m fairly new to iPhone development and certainly to iPhone <em>game </em>development, so this will be a learning experience that I&#8217;ll share here.<br />
<span id="more-21"></span><br />
First, of course, is the concept. Despite many books on the subject, I&#8217;m not sure that there&#8217;s any magic process to coming up with an idea for a game or any other product. For me, this was just something that came to me one day. The key is taking the idea and developing something out of it, which is something I did in off times (waiting for bus, etc.). I decided that the idea held water, so I moved onto the next stage.</p>
<p>Second &#8211; I spent a bit of time writing down the concept that had been in my head and brainstorming other possibilities that may or may not make it into the game. What is written down still constitutes a fairly loose concept with no exact details. This is not a specification that could be handed off to an engineer to code. This is purely my ideas written down so I don&#8217;t forget them at the point that I start coding the product. In this particular instance, this amounts to 2 pages of stuff written down in my Moleskine (quad-ruled of course!). Once the game is released, I plan on releasing a scan of these notes on this blog to show you where I started and what I ended up with.</p>
<p>Just last week, I started coding the game. To begin, I decided to take an evolutionary approach to the implementation rather than drilling down into the details up front. I think this is the best approach given that I&#8217;ll be learning more about the iPhone platform  as I&#8217;m coding . I think this also encourages me to continuously refine the game on the fly.</p>
<p>So what have I been implementing so far?</p>
<p><strong>Game loop: </strong>A major portion of any game is the game loop.  Essentially, this is the pulse of your game where you move objects, do collision detection, and then redraw the contents.  There are various ways to approach this, but I am currently using a NSTimer set to fire 10 times a second.  A NSTimer is not guaranteed to fire at exactly the interval I specify, but it&#8217;s close enough for now that the rest of my code is assuming the interval is constant.  If I get to a point where the frame rate becomes variable due to excessive load, then I&#8217;ll investigate other methods to make it more steady or I&#8217;ll take the actual framerate into account when calculating how to move the objects in the game.</p>
<p><strong>Graphics: </strong>For now, I&#8217;m implementing the graphics using Core Graphics and just using simple drawing functions to draw into a <a href="http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html">CGContext</a>. I have never written OpenGL code, so that would be a roadblock to me in my quest to develop the game play.</p>
<p>For starting with a 2D game, I think using really simple graphics to start out with is a good idea.  I want to get the gameplay going and then enhance the look over time.  With a 3D game, I&#8217;m not sure that this this approach will work quite as well (and it may not apply to all 2D games), but depending on your game you might be able to get away with drawing spheres and boxes and then enhancing the 3D models over time.</p>
<p><strong>Input: </strong>I&#8217;m just using  <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/touchesEnded:withEvent:">-touchesEnded:withEvent:</a> in my view to handle input.  I don&#8217;t think I&#8217;ll need to get more complicated than that.</p>
<p>So what are the next steps?  In the immediate future, I will continue refining the game play. That&#8217;s the most important thing. If the game isn&#8217;t fun and well-balanced, then it&#8217;s just not going to succeed.</p>
<p>After I&#8217;m happy with the game play, I will loop back to refining the graphics which are far too abstract for a final product at the moment. I generally appreciate form over function, but from the perspective of the users of a game they will want attractive graphics instead of colored blobs. I will eventually see whether I can spice them up a bit just using Core Graphics. If I can &#8211; great!  Otherwise, I may investigate whether pre-drawn sprite bitmaps are the way to go. Or, I may still have to learn how to use OpenGL in order to get the look and effects I&#8217;m looking for in order to give this a good visual polish.</p>
<p>At some point, I&#8217;ll have to address sound effects for the game as well. I&#8217;m not quite sure where that fits in, but I figure that I&#8217;ll start working on that while I refine the game play. I have much to learn about this area.</p>
<p>Hopefully some of you will find this useful. I plan on posting some more notes on my progress as my work progresses.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buzzardsoft.com/2009/09/17/iphone-game-prototype/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

