<?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>Sinceriously &#187; crossword</title>
	<atom:link href="http://www.sinceriously.com/tag/crossword/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sinceriously.com</link>
	<description>Designment and Development</description>
	<lastBuildDate>Sun, 18 Jul 2010 01:36:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Crossword Web App, Part 6</title>
		<link>http://www.sinceriously.com/2009/03/crossword-web-app-part-6/</link>
		<comments>http://www.sinceriously.com/2009/03/crossword-web-app-part-6/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 20:31:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Designment]]></category>
		<category><![CDATA[crossword]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web app]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.sinceriously.com/?p=217</guid>
		<description><![CDATA[Although it&#8217;s easy to get Javascript to read from an XML file, pulling out the appropriate data can sometimes be tricky. Here are some tips to help you tame the XML beast. Part 6: Taming XML Let&#8217;s look at a typical XMLHttpRequest again. var url = 'xml/070814.xml';var xmlhttp = new XMLHttpRequest();&#160;if (xmlhttp != null) {xmlhttp.onreadystatechange [...]]]></description>
			<content:encoded><![CDATA[<p>Although it&#8217;s easy to get Javascript to read from an XML file, pulling out the appropriate data can sometimes be tricky. Here are some tips to help you tame the XML beast.</p>
<h1>Part 6: Taming XML</h1>
<p></p>
<p>Let&#8217;s look at a typical <code>XMLHttpRequest</code> again.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">var url = 'xml/070814.xml';</code><code class="code-breakout">var xmlhttp = new XMLHttpRequest();</code><code class="code-breakout">&nbsp;</code><code class="code-breakout">if (xmlhttp != null) {</code><code class="code-breakout" style="margin-left:18px;">xmlhttp.onreadystatechange = stateChange;</code><code class="code-breakout" style="margin-left:18px;">xmlhttp.open('GET', url, true);</code><code class="code-breakout" style="margin-left:18px;">xmlhttp.send(null);</code><code class="code-breakout">} else {</code><code class="code-breakout" style="margin-left:18px;">alert('Your browser does not support XMLHTTP.'); }</code><code class="code-breakout">}</code><code class="code-breakout">&nbsp;</code><code class="code-breakout">function stateChange() {</code><code class="code-breakout" style="margin-left:18px;">if (xmlhttp.readyState == 4) {</code><code class="code-breakout" style="margin-left:36px;">if (xmlhttp.status == 200) {</code><code class="code-breakout" style="margin-left:54px;">/*</code><code class="code-breakout" style="margin-left:54px;">A status of 200 means that the XML file was</code><code class="code-breakout" style="margin-left:54px;">loaded and parsed without error. At this point</code><code class="code-breakout" style="margin-left:54px;">you'll want to sort through all of the data so</code><code class="code-breakout" style="margin-left:54px;">that it can be used by your program. I'll give</code><code class="code-breakout" style="margin-left:54px;">you some tips on how to do this in the next</code><code class="code-breakout" style="margin-left:54px;">update.</code><code class="code-breakout" style="margin-left:54px;">*/</code><code class="code-breakout" style="margin-left:36px;">} else {</code><code class="code-breakout" style="margin-left:54px;">alert('Problem retrieving XML data.');</code><code class="code-breakout" style="margin-left:36px;">}</code><code class="code-breakout" style="margin-left:18px;">}</code><code class="code-breakout">}</code></div>
<p><span>Figure 1. The basic structure of an XMLHttpRequest</span></div>
<p></p>
<p><span id="more-217"></span></p>
<p>If the request succeeds without error, then we can use the <code>xmlhttp</code> object to access the contents of the loaded XML file. To understand how to work with an <code>XMLHttpRequest</code> object, let&#8217;s relate it to something a little more familiar to Web coders: the Javascript <code>Document</code> object.</p>
<p><code>document.getElementsByName('across')</code> will return an array containing all of the elements on your Web page whose <code>name</code> <em>attribute</em> is &#8220;across.&#8221; For example, <code>&lt;div name="across"&gt;</code>.</p>
<p><code>xmlhttp.responseXML.getElementsByTagName('across')</code> will return an array containing all of the &#8220;across&#8221; XML nodes. For example, <code>&lt;across&gt;Data&lt;/across&gt;</code>.</p>
<p>Nodes can have both <em>attributes</em> and <em>values</em>. Review Figure 2.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code><code class="code-breakout">&lt;editor&gt;Timothy Parker&lt;/editor&gt;</code><code class="code-breakout">&lt;across&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a1 a="POET" c="Burns or Byron" n="1" cn="1" /&gt;</code><code class="code-breakout">&lt;/across&gt;</code></div>
<p><span>Figure 2. <strong>c</strong> is an attribute of the <strong>a1</strong> node.<br />&#8220;Timothy Parker&#8221; is the value of the <strong>editor</strong> node.</span></div>
<p></p>
<p><code>getElementsByTagName</code> will always return an array. In the example above there is only one <code>a1</code> node, therefore there&#8217;s no reason to keep an <em>array</em> of <code>a1</code> nodes. Instead, using the code below, we can save only the first returned node (since that&#8217;s all that exists).</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">var a1Node = xmlhttp.responseXML.getElementsByTagName('a1')[0];</code></div>
<p><span>Figure 3. Save a reference to the <strong>a1</strong> XML node in a variable named <strong>a1Node</strong>.</span></div>
<p></p>
<p>Now that we&#8217;ve captured the <code>a1</code> node specifically, we can access its <code>c</code> <em>attribute</em> using this simple code: <code>var c = a1.getAttribute('c');</code>.</p>
<p>Accessing node <em>attributes</em> is easy, but accessing node <em>values</em> is a little more confusing. Figure 4 demonstrates how to access the <em>value</em> of the <code>editor</code> node.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">var editor = xmlhttp.responseXML.getElementsByTagName('editor')[0];</code><code class="code-breakout">var editorValue = editor.firstChild.nodeValue;</code></div>
<p><span>Figure 4. Accessing the value of the <strong>editor</strong> node.</span></div>
<p></p>
<p>The <code>firstChild</code> method returns the first child of a node, duh. But the <code>editor</code> node does not appear to have any children. Well, it apparently (or not so apparently) does. When attempting to access the <em>value</em> of a node, imagine the value text as being a node itself. Access the <code>nodeValue</code> of the &#8220;text node&#8221; and you&#8217;ll get the result you&#8217;re looking for. Or, in more simple terms, always use <code>.firstChild.nodeValue</code> to access the value of a node.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code><code class="code-breakout">&lt;across&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a1 a="POET" c="Burns or Byron" n="1" cn="1" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a2 a="BLAB" c="Give everything away" n="6" cn="5" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a3 a="TALKS" c="Gives everything away" n="11" cn="9" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a4 a="ALSO" c="Too" n="16" cn="14" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a5 a="YOHO" c="Exclamation by Captain Jack Sparrow" n="21" cn="15" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a6 a="ELIOT" c="'A Cooking Egg' writer" n="26" cn="16" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a7 a="LIAR" c="Ananias, for one" n="31" cn="17" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a8 a="PREY" c="Target in the wild" n="36" cn="18" /&gt;</code><code class="code-breakout" style="margin-left:18px;">&lt;a9 a="ALONE" c="In isolation" n="41" cn="19" /&gt;</code><code class="code-breakout">&lt;/across&gt;</code></div>
<p><span>Figure 5. Another XML example.</span></div>
<p></p>
<p>In the above example, all of the <code>across</code> child nodes are named differently, so it would be cumbersome to <code>getElementsByTagName</code> each one separately. Instead, take advantage of the <code>childNodes</code> collection to return an array of the nodes.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout"> var acrossNodes = xmlhttp.responseXML.getElementsByTagName('across')[0].childNodes;</code></div>
<p><span>Figure 6. Save all of the <strong>across</strong> child nodes to an array.</span></div>
<p></p>
<p>There is more to learn about <code>XMLHttpRequest</code>, but by simply knowing how to use the <code>getElementsByTagName</code>, <code>getAttribute</code>, <code>firstChild</code> and <code>nodeValue</code> methods and the <code>childNodes</code> collection, you&#8217;ll have an easy time retrieving all types of data from XML documents.</p>
<p>Before I close this lengthy post, there is one more thing I&#8217;d like to mention with regards to XML files. It appears that you can not use Javascript to access local XML files using XMLHttpRequest, you can only access files found on a domain. I am completely perplexed as to why this is and if anyone  has knowledge of the reason, or knows a workaround, I&#8217;d love to hear from you.</p>
<p><strong>&mdash; Ryan</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://js-kit.com/rss/www.sinceriously.com/p=217</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crossword Web App, Part 5</title>
		<link>http://www.sinceriously.com/2009/03/crossword-web-app-part-5/</link>
		<comments>http://www.sinceriously.com/2009/03/crossword-web-app-part-5/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 21:33:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Designment]]></category>
		<category><![CDATA[crossword]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.sinceriously.com/?p=196</guid>
		<description><![CDATA[When I first started developing this crossword tutorial, I wanted the end game to access USA Today’s crossword XML feed directly and offer a new game each day. Sadly, their feed is secured. Although I can track it down, view its source in a Web browser, save to a local file and upload to my [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started developing this crossword tutorial, I wanted the end game to access USA Today’s crossword XML feed directly and offer a new game each day. Sadly, their feed is secured. Although I can track it down, view its source in a Web browser, save to a local file and upload to my server, I cannot get my code to access the file directly from their server. Keep that in mind when we reach the end of this tutorial. You’ll be able to play one completed game, but don’t get too attached. There’s not much replayability.</p>
<h1>Part 5: Importing From XML</h1>
<p></p>
<p>Most programs, including games, require data. More often than not this data must be updated regularly so as to sustain the usefulness of the application. This type of data is usually stored externally (out of the application&#8217;s main code) since it makes very little sense to require the application&#8217;s user to download a new version of the program every day in order to receive the latest and greatest data. Therefore, with respect to our game, it makes a great deal of sense to store the data for each crossword puzzle in an external XML file. This way each puzzle can easily be loaded individually by referencing a different XML file.</p>
<p><span id="more-196"></span></p>
<p>To import data from an XML file, we use the XMLHttpRequest Javascript object as follows.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">var url = 'xml/070814.xml';</code><code class="code-breakout">var xmlhttp = new XMLHttpRequest(); </code><code class="code-breakout">&nbsp;</code><code class="code-breakout">if (xmlhttp != null) {</code><code class="code-breakout" style="margin-left:18px;">xmlhttp.onreadystatechange = stateChange;</code><code class="code-breakout" style="margin-left:18px;">xmlhttp.open('GET', url, true);</code><code class="code-breakout" style="margin-left:18px;">xmlhttp.send(null);</code><code class="code-breakout">} else {</code><code class="code-breakout" style="margin-left:18px;">alert('Your browser does not support XMLHTTP.'); }</code><code class="code-breakout">}</code><code class="code-breakout">&nbsp;</code><code class="code-breakout">function stateChange() {</code><code class="code-breakout" style="margin-left:18px;">if (xmlhttp.readyState == 4) {</code><code class="code-breakout" style="margin-left:36px;">if (xmlhttp.status == 200) {</code><code class="code-breakout" style="margin-left:54px;">/*</code><code class="code-breakout" style="margin-left:54px;">A status of 200 means that the XML file was</code><code class="code-breakout" style="margin-left:54px;">loaded and parsed without error. At this point</code><code class="code-breakout" style="margin-left:54px;">you'll want to sort through all of the data so</code><code class="code-breakout" style="margin-left:54px;">that it can be used by your program. I'll give</code><code class="code-breakout" style="margin-left:54px;">you some tips on how to do this in the next</code><code class="code-breakout" style="margin-left:54px;">update.</code><code class="code-breakout" style="margin-left:54px;">*/</code><code class="code-breakout" style="margin-left:36px;">} else {</code><code class="code-breakout" style="margin-left:54px;">alert('Problem retrieving XML data.');</code><code class="code-breakout" style="margin-left:36px;">}</code><code class="code-breakout" style="margin-left:18px;">}</code><code class="code-breakout">}</code></div>
<p><span>Figure 1. Using XMLHttpRequest to load and read an XML file</span></div>
<p></p>
<p>We&#8217;ll talk more about reading from XML files in the next update.</p>
<p><strong>&mdash;Ryan</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://js-kit.com/rss/www.sinceriously.com/p=196</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crossword Web App, Part 4</title>
		<link>http://www.sinceriously.com/2009/03/crossword-web-app-part-4/</link>
		<comments>http://www.sinceriously.com/2009/03/crossword-web-app-part-4/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 21:35:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Designment]]></category>
		<category><![CDATA[crossword]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[preload images]]></category>
		<category><![CDATA[uri kitchen]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.sinceriously.com/?p=169</guid>
		<description><![CDATA[Unlike desktop applications, or native iPhone apps, whose code is pre-compiled with assets prepped and readily available in nearby bundles, Web apps are burdened with the task of downloading their assets (HTML, CSS, images, scripts, etc) in real time, as a user is attempting to interact with the app. In this context I&#8217;m referring to [...]]]></description>
			<content:encoded><![CDATA[<p><span>Unlike desktop applications, or native iPhone apps, whose code is pre-compiled with assets prepped and readily available in nearby bundles, Web apps are burdened with the task of downloading their assets (HTML, CSS, images, scripts, etc) in real time, as a user is attempting to interact with the app.</span> <span class="note">In this context I&#8217;m referring to a Web site as an &#8220;app&#8221; since so many of today&#8217;s Web 2.0 sites are robust enough to be considered applications. Also, Apple has often referred to iPhone Web sites as Web apps.</span> <span>HTML, CSS and scripts are generally low weight files, a couple of kilobytes a piece (some are larger, but most aren&#8217;t) and can be downloaded quickly. Images, on the other hand, can be very large&mdash;upwards of 100K in some instances. Downloading large images can be time consuming, especially on mobile devices, therefore you can improve your application&#8217;s user experience by downloading images ahead of time.</span></p>
<p>This part of the tutorial is actually not going to explain proper procedures for preloading images. There are a number of methods available, all of which can be found by doing a simple <a href="http://www.google.com/search?client=safari&#038;rls=en-us&#038;q=preload+images&#038;ie=UTF-8&#038;oe=UTF-8" onclick="window.open(this.href); return false;">Google search for &#8220;preload images&#8221;</a>. This article will instead concentrate on ways to reduce the necessity of preloading altogether by means of self-contained data and CSS Sprites.</p>
<p>I&#8217;ll start off by briefing explaining the importance of CSS Sprites (since Part 4 below will explain how to use self-contained data). <a href="http://www.alistapart.com/articles/sprites" onclick="window.open(this.href); return false;">An in-depth discussion of CSS Sprites can be read on A List Apart.</a> In a nutshell, a sprite map is a collection of smaller images mapped onto one large image. By combining images, you will reduce server requests and speed up download times. CSS Sprites especially come in handy when dealing with hovers.</p>
<p><span id="more-169"></span></p>
<p>Without sprites, displaying a different image for the hover state of an element requires making an extra call to the server for the new asset. This results in another download (at the time of mouseover), which can take time and create jerky mouseover experiences (especially in Internet Explorer). If a sprite map is used instead, the sprite can be setup to contain images for both the default state as well as the hover state. The sprite is downloaded as the page loads (if the element which will use the sprite is initially embedded on the page), and voil&aacute;, the hover state is downloaded with it and ready for use.</p>
<p>I&#8217;ve used sprites a couple of times on this site. To demonstrate how easy they are to use, let&#8217;s take a look at the &#8220;press&#8221; button at the bottom of the page.</p>
<div class="illustration"><img src="http://www.sinceriously.com/wp-content/themes/FREEmium/post-img/sprite_example.gif" alt="Example sprite image" width="286" height="106" /><span>Figure 1. Example sprite image</span><br />&nbsp;</div>
<p></p>
<p>The sprite is illustrated above. <span class="note">The actual image is a PNG and contains elements which would be hard to decipher on a light grey background. The turquoise box was added to make things more viewable.</span> Using an anchor tag as a button, we can crop out the backgrounds we need for the default and hover states using the following CSS.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">#press { background:url("img/press.png"); width:50px; height:50px; display:block; text-indent:-200em; overflow:hidden; }</code><code class="code-breakout">#press:hover { background-position:0 -50px; }</code></div>
<p><span>Figure 2. &#8220;Press&#8221; Button CSS</span></div>
<p></p>
<p><em>Background, width and height styles:</em> Because we are cropping the button to a width and height of 50 pixels, it is not necessary to specify a background position for the default state. Why? The default background appears at the top of our sprite. So as long as we assign a width and height that are the exact dimensions of the default background, the remainder of the background will extended past the boundaries of the button and will not be seen.</p>
<p><em>Display style:</em> By default, anchor tags display inline, so in order to represent the anchor as a button (and specify things like width and height), we need to force the anchor to display as a block element.</p>
<p><em>Text-indent and overflow styles:</em> If, in your markup, you include text within the anchor tag (for example: <code>&lt;a id="press" href="javascript:void(0)" onclick="dropBlock()"&gt;Press&lt;/a&gt;</code>), you can hide the text by assigning a negative text indent and hiding overflow.</p>
<p><em>The hover state:</em> Now, all we need to do in order to fire up the hover state of the button is offset the top background position of the background enough so that the hover image is used instead of the default image. In this case, we need to offset by 50 pixels. <span class="note">When a sprite map only includes two image states, the offset can be either positive or negative. Both will achieve the same result. When dealing with sprites with three or more states, I recommend strictly using negative values. You&#8217;ll understand why as you experiment more with sprites.</span></p>
<p>And that&#8217;s CSS Sprites in a nutshell. Now on to the actual Part 4 update where I&#8217;ll discuss self-contained data.</p>
<h1>Part 4: &#8216;Preloading&#8217; Commonly Used Game Assets</h1>
<p></p>
<p>If you&#8217;ve ever used Dreamweaver, you&#8217;re probably familiar with the code that&#8217;s used to preload images:</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout previous-code">function simplePreload() {</code><code class="code-breakout previous-code" style="margin-left:18px;">var args = simplePreload.arguments;</code><code class="code-breakout previous-code" style="margin-left:18px;">document.imageArray = new Array(args.length);</code><code class="code-breakout previous-code" style="margin-left:18px;">for (var i = 0; i < args.length; i++) {</code></code><code class="code-breakout" style="margin-left:36px;">document.imageArray[i] = new Image;</code><code class="code-breakout previous-code" style="margin-left:36px;">document.imageArray[i].src = args[i];</code><code class="code-breakout previous-code" style="margin-left:18px;">}</code><code class="code-breakout previous-code">}</code></div>
<p><span>Figure 3. Dreamweaver preload script</span></div>
<p></p>
<p>Look at the highlighted line. In Javascript you can create Image objects. By doing so, you can store images in the DOM&#8217;s (Document Object Model) memory and quickly access them later. But preloading images in this fashion still requires an HTTP call out to the image so that it can be downloaded. When designing games for the iPhone, we want to limit the number of HTTP requests as much as possible. There&#8217;s actually a way to embed some of your images in your Javascript file so that there&#8217;s no need to download them.</p>
<p>If you&#8217;ve ever tried to open a GIF or JPEG in a text editor you&#8217;ll notice that the guts of the image are a bunch of letters, numbers and symbols. There&#8217;s a free program online, called the URI Kitchen that will read an image and print out the letter/number/symbol/gremlin guts for you.</p>
<p>To use the program, go to <a href="http://software.hixie.ch/utilities/cgi/data/data" onclick="window.open(this.href); return false;">URI Kitchen</a>, upload a file and then copy the resulting data from the address bar. Here&#8217;s the data I get when feeding the program a graphic of the number 5 (one of the numbers used to mark the crossword grid):</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">data:image/gif;base64,R0lGODlhAwAFAIAAAP%2F%2F%2F39%2FfyH5B AAAAAAALAAAAAADAAUAAAIFjANgqVsAOw%3D%3D</code></div>
<p><span>Figure 4. URI Kitchen image data</span></div>
<p></p>
<p>Pretty, huh? Now, take that data, and use it as follows:</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">var five = new Image();</code><code class="code-breakout">five.src = 'data:image/gif;base64,R0lGODlhAwAFAIAAAP%2F%2F%2F39%2FfyH5B AAAAAAALAAAAAADAAUAAAIFjANgqVsAOw%3D%3D'; </code></div>
<p><span>Figure 5. Using self-contained data to generate an image</span></div>
<p></p>
<p>I can now access <code>five</code> anytime I want to load that image in my game, and since it&#8217;s embedded in the code there&#8217;s no need to run off to the Internet to fetch it. I can draw the image to the canvas (at coordinate 100, 50) like this: <code>ctx.drawImage(questionMark, 100, 50)</code>.</p>
<p>Now, you won&#8217;t want to use this approach for every image in your game. You&#8217;ll still have to elegantly handle load times for large images. But this approach works great for smaller, commonly used images. What are the most commonly used assets in a crossword puzzle? The numbers used to label the grid, and the letters that will spell out each word. And those are the exact images that we&#8217;ll &#8220;preload&#8221; into Javascript using this method.</p>
<p>And this has officially been the longest blog post I&#8217;ve ever written. I hope you&#8217;ve enjoyed it!</p>
<p><strong>&mdash;Ryan</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://js-kit.com/rss/www.sinceriously.com/p=169</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crossword Web App, Part 3</title>
		<link>http://www.sinceriously.com/2009/03/crossword-web-app-part-3/</link>
		<comments>http://www.sinceriously.com/2009/03/crossword-web-app-part-3/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 05:15:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Designment]]></category>
		<category><![CDATA[crossword]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.sinceriously.com/?p=120</guid>
		<description><![CDATA[This part of the tutorial makes mention of the canvas tag. When Mac OS X 10.4 was released, Safari began supporting a new feature called the canvas. The canvas (refered to as CSS Canvas on the Safari 4 features page) provides a method for drawing arbitrary content in a Web page. This extension lets you [...]]]></description>
			<content:encoded><![CDATA[<p>This part of the tutorial makes mention of the <code>canvas</code> tag. When Mac OS X 10.4 was released, Safari began supporting a new feature called the canvas. The canvas (refered to as CSS Canvas on the <a href="http://www.apple.com/safari/features.html" onclick="window.open(this.href); return false;">Safari 4 features page</a>) provides a method for drawing arbitrary content in a Web page. This extension lets you reserve an area of your web page or widget and use rendering calls like those found in Quartz (or ActionScript) to paint complex paths and shapes in that area. CSS Canvas was heavily utilized by the initial offering of Dashboard widgets released by Apple.</p>
<p>Safari, Firefox, Dashboard, and all other <a href="http://webkit.org/" onclick="window.open(this.href); return false;">WebKit</a>-based applications, including Safari for the iPhone, support CSS Canvas. There&#8217;s even <a href="http://www.geeksmack.net/microsoft/106-rumor-ie-9-to-use-webkit.html" onclick="window.open(this.href); return false;">rumor that Internet Explorer 9 will use WebKit</a>, allowing it access to CSS Canvas as well. So it really makes a lot of sense to start learning how to use CSS Canvas now, so that you can build really cool Web sites that take advantage of it later.</p>
<h1>Part 3: Jumping Into Code</h1>
<p></p>
<p>Let&#8217;s start programming this game. The <code>canvas</code> tag, supported by Firefox and Safari, is a really great way to draw to (or animate) a Web page. Since the iPhone <a href="http://www.macrumors.com/2008/02/11/adobe-flash-support-for-iphone-coming-alongside-sdk/" onclick="window.open(this.href); return false;">does not yet support Flash</a>, utilizing the canvas makes a lot of sense. Since more qualified people than ! have already written great tutorials on <a href="http://developer.mozilla.org/en/docs/Canvas_tutorial" onclick="window.open(this.href); return false;">how to use the canvas</a>, it may behoove you to read up a bit if you become confused with what follows.</p>
<p><span id="more-120"></span></p>
<p>Let&#8217;s code the grid. There are two ways we can display it. We can use the canvas to draw the grid. Or we can create 225 17&#215;17 pixel <strong>div</strong> elements and float them all to the left within a 270&#215;270 pixel parent <strong>div</strong>. The first option sounds easier, but we&#8217;re actually going to do a little of both.</p>
<p><span class="note"><strong>Note:</strong> Yesterday&#8217;s illustration stated that the grid takes up 271&#215;271 pixels, yet we mention here that the outer <strong>div</strong> that holds all of the inner squares is 270&#215;270 pixels. This is because the inner squares do not include the outer stroke that surrounds the grid. The outer stroke (and all inner grid lines) are part of the background image. The inner squares have a 1px left margin to separate them from one another, so: (1+17)*15 = 270.</span></p>
<p>First we&#8217;ll use the canvas to draw the visual part of the grid. Here is some simplified code:</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">&lt;div id="squares"&gt;&lt;/div&gt;</code><code class="code-breakout">&lt;canvas id="crossword" width="269" height="269"&gt;&lt;/canvas&gt;</code></div>
<p><span>Figure 1. Simplified CSS Canvas implementation</span></div>
<p></p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout">var ctx = document.getElementById('crossword').getContext('2d');</code><code class="code-breakout">ctx.fillStyle = '#ffffff';</code><code class="code-breakout">for (var i = 0; i < 225; i++) {</code></code><code class="code-breakout" style="margin-left:18px;">ctx.fillRect((i-Math.floor(i/15)*15)*18, Math.floor(i/15)*18, 17, 17);</code><code class="code-breakout">}</code></div>
<p><span>Figure 2. JavaScript to draw the grid to the canvas</span></div>
<p></p>
<p>The code above will simply draw out 225 white squares, positioned exactly where we want them on the grid. It does not yet determine which squares should be black (the regions of the grid that are not part of the puzzle). We&#8217;re ultimately going to read from an XML file to understand which squares are white and which are black. We&#8217;ll get to that later.</p>
<p>The user will be interacting with the grid in order to read and solve clues, so we also need a separate clickable region for each of the 225 inner squares. Let&#8217;s add that logic to the for loop.</p>
<div class="illustration">
<div class="code-wrap"><code class="code-breakout previous-code">for (var i = 0; i < 225; i++) {</code></code><code class="code-breakout previous-code" style="margin-left:18px;">ctx.fillRect((i-Math.floor(i/15)*15)*18, Math.floor(i/15)*18, 17, 17);</code><code class="code-breakout" style="margin-left:18px;">var newSquare = document.createElement('div');</code><code class="code-breakout" style="margin-left:18px;">document.getElementById('squares').appendChild(newSquare);</code><code class="code-breakout" style="margin-left:18px;">newSquare.className = 'square';</code><code class="code-breakout" style="margin-left:18px;">newSquare.id = i;</code><code class="code-breakout" style="margin-left:18px;">newSquare.name = i;</code><code class="code-breakout" style="margin-left:18px;">newSquare.onclick = function() {</code><code class="code-breakout" style="margin-left:36px;">// code to execute onclick</code><code class="code-breakout" style="margin-left:18px;">};</code><code class="code-breakout previous-code">}</code></div>
<p><span>Figure 3. JavaScript to create clickable (touchable) squares for the grid</span></div>
<p></p>
<p>We&#8217;ve given each &#8220;touchable&#8221; <strong>div</strong> an <em>id</em> and <em>name</em> so that, when touched, we can figure out which clues they belong to. More on that later.</p>
<p>For today, that is all. Tomorrow I&#8217;ll provide a neat trick for embedding images directly into a Web page. It&#8217;s a great way to &#8220;preload&#8221; images. Very cool indeed.</p>
<p><strong>&mdash;Ryan</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://js-kit.com/rss/www.sinceriously.com/p=120</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Crossword Web App, Part 2</title>
		<link>http://www.sinceriously.com/2009/03/crossword-web-app-part-2/</link>
		<comments>http://www.sinceriously.com/2009/03/crossword-web-app-part-2/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 06:23:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Designment]]></category>
		<category><![CDATA[crossword]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.sinceriously.com/?p=110</guid>
		<description><![CDATA[When I originally posted part two of this tutorial last year, I prefaced it with news of an &#8220;imminent&#8221; release of Adobe&#8217;s Flash for the iPhone. Well, a year has passed and still no Flash. Around a month ago, MacRumors announced a collaboration with Adobe and Apple on a Flash solution, but I&#8217;ve since read [...]]]></description>
			<content:encoded><![CDATA[<p>When I originally posted part two of this tutorial last year, I prefaced it with news of an &#8220;imminent&#8221; release of Adobe&#8217;s Flash for the iPhone. Well, a year has passed and still no Flash. Around a month ago, MacRumors announced <a href="http://www.macrumors.com/2009/01/31/adobe-and-apple-working-on-flash-for-iphone/" onclick="window.open(this.href); return false;">a collaboration with Adobe and Apple on a Flash solution</a>, but I&#8217;ve since read that business negotiations are delaying that initiative. So we&#8217;re still a no go.</p>
<p>I mention Flash because it would seem that the inclusion of the plug-in would open the door to many established and seasoned Flash developers who are not savvy with HTML/CSS/JavaScript or Objective-C (for SDK development). But with the <a href="http://www.macrumors.com/2009/02/06/css-animation-coming-to-safari-already-in-iphone-less-dependence-on-flash/" onclick="window.open(this.href); return false;">introduction of CSS animation</a>, which the iPhone (and now Safari 4 beta) already support, creating visually intriguing web user interfaces (for games or other web apps) is more plausible than ever before, even without Flash.</p>
<p>It may not seem realistic to create iPhone web app <strong>games</strong> anymore, since the release of the SDK over a year ago, but iPhone Web designers and developers can still strive to create visually impressive web experiences. And some of these tips may help towards that cause.</p>
<h1>Part 2: Design Considerations</h1>
<p></p>
<p>When designing web app games for the iPhone keep in mind that although the screen&#8217;s resolution is 320&#215;480 pixels, some of the vertical pixels are lost to the status bar, address bar and lower toolbar&#8230; 64 pixels to be exact. So, if you want your entire game to display &#8220;above the fold,&#8221; design it to be 320&#215;416 pixels. (Above the fold is a reference web designers throw around a lot to appear cool. It refers to the topmost part of a Web page. The area that is initially viewable. The content that shows up as you scroll down the page is &#8220;below the fold.&#8221;)</p>
<p><span id="more-110"></span></p>
<div class="illustration"><img src="http://www.sinceriously.com/wp-content/themes/FREEmium/post-img/crossword_illo2.gif" alt="Crossword puzzle user interface components" width="426" height="451" /><span>Figure 1. Crossword puzzle user interface components</span><br />&nbsp;</div>
<p></p>
<p>If you look at a printed crossword puzzle you&#8217;ll notice that the game consists of two main parts: the grid, and the &#8220;across&#8221; and &#8220;down&#8221; clues. Both take up a lot of real estate. So how do we fit everything onto the iPhone screen?</p>
<p>First let&#8217;s discuss the grid (or board, whatever you&#8217;d like to call it). The squares that make up the grid need to be small enough so that a 15&#215;15 matrix will fit within the design. They also need to be large enough so that even a person with “fat fingers” can press a single square. After mocking up a number of grid sizes I realized that although I could theoretically size each individual square at 19&#215;19 pixels and still fit all 225 (15 rows x 15 columns) on the screen, I didn&#8217;t have much room for anything else. So I settled on 17&#215;17. This means that we loose 271&#215;271 pixels to the grid.</p>
<p>Since a title also accompanies each puzzle, very little room is left for the clues. It will be impossible to display them all at once, so instead let&#8217;s display relevant clues when the user clicks on a particular row/column. We&#8217;ll talk about how this is going to work later.</p>
<p>That&#8217;s all for today. We’ll start coding tomorrow.</p>
<p><strong>&mdash;Ryan</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://js-kit.com/rss/www.sinceriously.com/p=110</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building an iPhone Web App Crossword Puzzle</title>
		<link>http://www.sinceriously.com/2009/03/building-an-iphone-web-app-crossword-puzzle/</link>
		<comments>http://www.sinceriously.com/2009/03/building-an-iphone-web-app-crossword-puzzle/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 02:44:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Designment]]></category>
		<category><![CDATA[crossword]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.sinceriously.com/?p=93</guid>
		<description><![CDATA[In addition to me explaining the history behind some of the projects I&#8217;ve been tinkering with over the years, I want this blog to serve as an educational tool for aspiring designers and developers. And so, without further ado, the first of (hopefully) many tutorials. This tutorial was originally written in February 2008 (pre iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>In addition to me explaining the history behind some of the projects I&#8217;ve been tinkering with over the years, I want this blog to serve as an educational tool for aspiring designers and developers. And so, without further ado, the first of (hopefully) many tutorials.</p>
<p>This tutorial was originally written in February 2008 (pre iPhone SDK days) and was featured on a now defunct iPhone blog. I will repost the original articles along with update notes, where appropriate.</p>
<h1>Part 1: Things to Keep In Mind</h1>
<p></p>
<p>There are a couple of things to keep in mind when considering iPhone game development. The most important is that iPhone developers currently do not have access to many of the usability features that make the iPhone great. Things like pinch, expand, slide, drag, drop, etc. That may change when the SDK is announced later this month, but for now all we can respond to is a single touch (click). <span class="note">(<strong>March 2009 note:</strong> The SDK obviously now provides tools for developers to create amazing <strong>native</strong> apps, all of which include features like pinch, expand, slide, drag and drop, etc. But iPhone <strong>web</strong> apps are <em>still</em> limited to responding to only one action: a single touch of the screen.)</span></p>
<p><span id="more-93"></span></p>
<p>Additionally, all of the applications must be built in Safari. Don&#8217;t get me wrong, I for one am more than happy to use Safari as my development environment. After all, HTML/Javascript development is what I know. It&#8217;s what I&#8217;ve spent the last 10 years working with. So I know how to do really amazing things with that medium. Still, Safari on the iPhone is less responsive than it is on your Mac or PC. <span class="note">(<strong>March 2009 note:</strong> <a href="http://www.apple.com/safari" onclick="window.open(this.href); return false;">Apple just released Safari 4 (beta)</a>, which includes the “Nitro JavaScript Engine,&#8221; said to execute JavaScript up to 6 times faster than Internet Explorer 8 and up to 4 times faster than Firefox 3.1. There are no known plans to upgrade the iPhone version of Safari to 4.0, but the potential JavaScript speed increases would be extremely welcomed. <a href="http://www.macrumors.com/2009/02/25/safari-4-tips-tricks-and-special-effects/" onclick="window.open(this.href); return false;">For an actual unbiased JavaScript speed comparison test, check out this article on MacRumors.</a> )</span> For instance, there is a lag between when you press something on the page and when you can press something else on the page. The lag is only about a second, but it should be kept in mind when you begin thinking about the type of game that you want to create. Because of the lag, slower-paced games make more sense. Therefore developing a puzzle game for this tutorial was a no brainer. After all, there&#8217;s not much need to race your way through a crossword puzzle.</p>
<div class="illustration"><img src="http://www.sinceriously.com/wp-content/themes/FREEmium/post-img/crossword_illo1.gif" alt="Crossword puzzle design, along with dimensions" width="426" height="451" /><span>Figure 1. Crossword puzzle design, along with dimensions </span><br />&nbsp;</div>
<p></p>
<p>Besides the fact that a crossword puzzle was a slower-paced game, this type of game also provided some interesting usability dilemmas, but we&#8217;ll get into those with the next update (we&#8217;ll also discuss design considerations then). For now, take a look at the near-finished design above. Though I&#8217;ve started some of the development of this game, there is much yet to still do so things may change over the next two weeks. <span class="note">(<strong>March 2009 note:</strong>  My original design never was edited later in development. So the design you see is final.)</span></p>
<p>Since I originally got the idea to create a crossword puzzle while reading a daily edition of USA Today, it made sense to literally try and repurpose the online version of their game in an iPhone format. Come back for tomorrow&#8217;s update when we&#8217;ll take a look at some design considerations.</p>
<p><strong>&mdash;Ryan</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://js-kit.com/rss/www.sinceriously.com/p=93</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
