<?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>Code With Design</title>
	<atom:link href="http://codewithdesign.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codewithdesign.com</link>
	<description>web application development blog by Caleb Jonasson</description>
	<lastBuildDate>Thu, 27 Sep 2012 01:06:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>HTML5 Field Autofocus</title>
		<link>http://codewithdesign.com/2012/09/26/html5-field-autofocus/</link>
		<comments>http://codewithdesign.com/2012/09/26/html5-field-autofocus/#comments</comments>
		<pubDate>Thu, 27 Sep 2012 01:06:59 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[autofocus]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=630</guid>
		<description><![CDATA[This is a quick and dirty post because I found out with html5 you can do something like this. 1 &#60;input name=&#34;search&#34; id=&#34;search_field&#34; type=&#34;text&#34; autofocus=&#34;autofocus&#34; /&#62; Bam! Now you have an html5 auto focussing field. Don&#8217;t forget your doctype! Related posts: An Introduction to the Canvas
Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/' rel='bookmark' title='An Introduction to the Canvas'>An Introduction to the Canvas</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/09/26/html5-field-autofocus/"></g:plusone></div><p>This is a quick and dirty post because I found out with html5 you can do something like this.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="hmtl" style="font-family:monospace;">&lt;input name=&quot;search&quot; id=&quot;search_field&quot; type=&quot;text&quot; autofocus=&quot;autofocus&quot; /&gt;</pre></td></tr></table></div>

<p>Bam! Now you have an html5 auto focussing field. Don&#8217;t forget your doctype!</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=630&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/' rel='bookmark' title='An Introduction to the Canvas'>An Introduction to the Canvas</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/09/26/html5-field-autofocus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Arrays</title>
		<link>http://codewithdesign.com/2012/05/11/javascript-arrays/</link>
		<comments>http://codewithdesign.com/2012/05/11/javascript-arrays/#comments</comments>
		<pubDate>Fri, 11 May 2012 12:28:18 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[objects]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=623</guid>
		<description><![CDATA[Introductions An array is simply a list of data contained in one variable and accessed by indices. An example of an array would be an array of ages containing 0, 1, 2, 3 etc. The array doesn’t have to be integers, it can be an array of strings, objects or even arrays. 1 2 3 [...]
Related posts:<ol>
<li><a href='http://codewithdesign.com/2009/10/08/javascript-hoirzontal-menu/' rel='bookmark' title='Javascript Hoirzontal Menu'>Javascript Hoirzontal Menu</a></li>
<li><a href='http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/' rel='bookmark' title='Javascript Canvas: Basic Game Logic and Movement'>Javascript Canvas: Basic Game Logic and Movement</a></li>
<li><a href='http://codewithdesign.com/2010/03/29/java-tutorial-about-arrays-vs-static-arrays/' rel='bookmark' title='Java: Tutorial about Arrays vs Static Arrays'>Java: Tutorial about Arrays vs Static Arrays</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/05/11/javascript-arrays/"></g:plusone></div><h2 dir="ltr">Introductions</h2>
<p>An array is simply a list of data contained in one variable and accessed by indices. An example of an array would be an array of ages containing 0, 1, 2, 3 etc. The array doesn’t have to be integers, it can be an array of strings, objects or even arrays.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Create an array</span>
<span style="color: #003366; font-weight: bold;">var</span> ages <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">99</span><span style="color: #339933;">,</span><span style="color: #CC0000;">54</span><span style="color: #339933;">,</span><span style="color: #CC0000;">23</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Create another array</span>
<span style="color: #003366; font-weight: bold;">var</span> names <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span>“bill”<span style="color: #339933;">,</span> “bob”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Create a literal array</span>
<span style="color: #003366; font-weight: bold;">var</span> games <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>“minecraft”<span style="color: #339933;">,</span>”half life”<span style="color: #339933;">,</span>”freecell”<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Add values to an empty array</span>
<span style="color: #003366; font-weight: bold;">var</span> ages <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ages<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
ages<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
ages<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">9</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>It is important to know that the array is actually an object that contains values. Because this type is actually an object there are properties that can be called to help handle the information inside of the array.</p>
<h2 dir="ltr">Helper Functions And Properties</h2>
<p>In javascript, along with many other languages, there are functions built around arrays that will allow you, the developer, to better use them and be more efficient in your coding. The length property is one of the most commonly used properties when going through an array.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Going through the items in an array.</span>
<span style="color: #006600; font-style: italic;">// Create the array</span>
<span style="color: #003366; font-weight: bold;">var</span> ages <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span><span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Loop through using the length property</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ages.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Print out the items one by one with an alert.</span>
<span style="color: #339933;">&lt;</span>p dir<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;ltr&quot;</span><span style="color: #339933;">&gt;</span>alert<span style="color: #009900;">&#40;</span>ages<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Array push and pop are commonly used to add items to the array without having to get the position of where the item will be added yourself.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Create an array with one item</span>
<span style="color: #003366; font-weight: bold;">var</span> names <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>“bob”<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// push an item onto the array.</span>
names.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>“caleb”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// the resulting array will now be the same as it would be if you created it like this.</span>
<span style="color: #003366; font-weight: bold;">var</span> names <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>“bob”<span style="color: #339933;">,</span>”caleb”<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now we are going to pop an element off of the end of the array and return the item. This call not only returns the value but it will alter the array in memory changing the values within it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create a new array of names that we will play with</span>
<span style="color: #003366; font-weight: bold;">var</span> names <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>“chewbacca”<span style="color: #339933;">,</span>”yoda”<span style="color: #339933;">,</span>”skywalker”<span style="color: #339933;">,</span>”ben”<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> poppedValue <span style="color: #339933;">=</span> names.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// As a result the names array will no longer have “ben” in it and the poppedValue will contain the string “ben”;</span></pre></td></tr></table></div>

<h2 dir="ltr">Two Dimensional Array</h2>
<p>The concept of a 2D array can seem a little intimidating at first until you realize that you need to look at the data as columns and rows. Here is an example of what a 2D array would look like.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Creating a 2D array</span>
<span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
x<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
x<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In order to access a property within the second array you will just need to fetch the value using the key.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Display the item that is in the first column of the first row.</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Another way to create an array like this is to loop through the items upon creation.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Create the array container</span>
<span style="color: #003366; font-weight: bold;">var</span> names <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
names<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Go through the second dimension and set the values.</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Assign the value of the item to bob.</span>
names<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> “bob”<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Note: </strong> in strongly typed languages an array must consist of the same data types. Since javascript is not a strongly typed language; the information stored can consist of mixed data types.</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=623&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2009/10/08/javascript-hoirzontal-menu/' rel='bookmark' title='Javascript Hoirzontal Menu'>Javascript Hoirzontal Menu</a></li>
<li><a href='http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/' rel='bookmark' title='Javascript Canvas: Basic Game Logic and Movement'>Javascript Canvas: Basic Game Logic and Movement</a></li>
<li><a href='http://codewithdesign.com/2010/03/29/java-tutorial-about-arrays-vs-static-arrays/' rel='bookmark' title='Java: Tutorial about Arrays vs Static Arrays'>Java: Tutorial about Arrays vs Static Arrays</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/05/11/javascript-arrays/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Drive API</title>
		<link>http://codewithdesign.com/2012/05/10/google-drive-api/</link>
		<comments>http://codewithdesign.com/2012/05/10/google-drive-api/#comments</comments>
		<pubDate>Thu, 10 May 2012 16:09:59 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[drive]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=619</guid>
		<description><![CDATA[Introduction Google Drive is out! Yes that’s right, Google’s Drive project which allows users to store content onto a Google server and pull it from any device is now available. This product offers 5GB free to google users with additional packages for extra money. This is a pretty cool thing and not just because Google [...]
Related posts:<ol>
<li><a href='http://codewithdesign.com/2011/06/29/googles-plus-1-button-integration-and-options/' rel='bookmark' title='Google&#8217;s Plus 1 Button Integration And Options'>Google&#8217;s Plus 1 Button Integration And Options</a></li>
<li><a href='http://codewithdesign.com/2012/05/01/decrease-javascript-load-times-and-increase-script-speed/' rel='bookmark' title='Decrease Javascript Load Times and Increase Script Speed'>Decrease Javascript Load Times and Increase Script Speed</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/05/10/google-drive-api/"></g:plusone></div><h2 dir="ltr">Introduction</h2>
<p><a title="Google Drive" href="https://drive.google.com/start#home" target="_blank">Google Drive is out!</a> Yes that’s right, Google’s Drive project which allows users to store content onto a Google server and pull it from any device is now available. This product offers 5GB free to google users with additional packages for extra money.<strong><strong></strong></strong></p>
<p>This is a pretty cool thing and not just because Google is doing drop box properly but more so because they are doing drop box across the Google platforms and offering an API to those of us that are interested in developing for it.</p>
<h2 dir="ltr">My plans</h2>
<p>My plan over the next couple of days is to create a way to store server logs and general statistics for my server to the Google Drive. This will allow me to easily check on how things are going from my mobile device.</p>
<h2 dir="ltr">Google Drive API</h2>
<p>If you are interested in working with Google Drive than I suggest that you take a look at the API that Google has provided us. <a href="https://developers.google.com/drive/v1/reference/">https://developers.google.com/drive/v1/reference/</a></p>
<p>If you are going to work with the API that is available you will have to register your own app. <a href="https://developers.google.com/drive/register">https://developers.google.com/drive/register</a></p>
<h3 dir="ltr">Performance</h3>
<p>The API has some interesting features for performance. When performing an update you can receive a partial response. This response type will only return the specific fields that you ask for rather than the entire object. The API also supports a header type of gzip to allow for speedier and smaller sent and received packets of information.</p>
<p>For more information on Google Drive API performance: <a href="https://developers.google.com/drive/performance">https://developers.google.com/drive/performance</a></p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=619&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2011/06/29/googles-plus-1-button-integration-and-options/' rel='bookmark' title='Google&#8217;s Plus 1 Button Integration And Options'>Google&#8217;s Plus 1 Button Integration And Options</a></li>
<li><a href='http://codewithdesign.com/2012/05/01/decrease-javascript-load-times-and-increase-script-speed/' rel='bookmark' title='Decrease Javascript Load Times and Increase Script Speed'>Decrease Javascript Load Times and Increase Script Speed</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/05/10/google-drive-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Canvas: Basic Game Logic and Movement</title>
		<link>http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/</link>
		<comments>http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/#comments</comments>
		<pubDate>Wed, 09 May 2012 10:48:26 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[beginPath]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[lineTo]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[setInterval]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=611</guid>
		<description><![CDATA[Introduction If you are interested in writing a game in javascript using the new canvas tag than look no further. In this lesson I will be going over the game loop and what is required to get started with your own. If you have not yet gone through the introduction to the canvas you should [...]
Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/' rel='bookmark' title='An Introduction to the Canvas'>An Introduction to the Canvas</a></li>
<li><a href='http://codewithdesign.com/2011/05/19/javascript-settimeout-firing-immediately/' rel='bookmark' title='JavaScript: setTimeout Firing Immediately'>JavaScript: setTimeout Firing Immediately</a></li>
<li><a href='http://codewithdesign.com/2009/10/08/javascript-hoirzontal-menu/' rel='bookmark' title='Javascript Hoirzontal Menu'>Javascript Hoirzontal Menu</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/"></g:plusone></div><h2>Introduction</h2>
<p>If you are interested in writing a game in javascript using the new canvas tag than look no further. In this lesson I will be going over the game loop and what is required to get started with your own. If you have not yet gone through the introduction to the canvas you should click here. It only takes a couple minutes to go through and it will have the required code for this lesson.</p>
<h2>The Basic Loop</h2>
<p>In order to create a loop we are going to base it off of seconds using the set_interval() function. This function will allow us to call on a function x times per second. This is a good function to use when making a loop based game because it will wait for the function to finish before calling on it again even if the time is exceeded.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// call on a function every 100 milliseconds.</span>
setInterval<span style="color: #009900;">&#40;</span>“methodName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>”<span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Drawing to the canvas</h2>
<p>For now we are going to simply draw to the canvas using a draw function. You can call on a class.method in the set interval function. In the draw function that we are creating, we are going to have to draw something to the canvas. In the following code we will draw a line from point a to point b.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
ctx.<span style="color: #660066;">strokeStyle</span> <span style="color: #339933;">=</span> “#<span style="color: #CC0000;">333333</span>”<span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">beginPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">50</span><span style="color: #339933;">,</span><span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">stroke</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If the setInterval function has been properly setup, to take the draw function, than you should see a line appear on the canvas. Now lets get a little wild and crazy and give that line some movement.</p>
<h2>Layers</h2>
<p>The canvas works in layers. If you draw something to it, the item will stay until something has been drawn over it. Because of this the canvas needs to be reset and will need to be reset and have everything drawn back on to it in layers from the background to the foreground.</p>
<p>In a two dimensional game you are going to want to draw the items from the bottom up. The items should be drawn in the following order if you are looking at the ground from a birds eye view.</p>
<p>Draw the dirt<br />
Draw the grass<br />
Draw the trees<br />
Draw the birds</p>
<h2>Movement</h2>
<p>Create public variables for x position, y position and counter.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> posX <span style="color: #339933;">=</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> posY <span style="color: #339933;">=</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> counter <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Within the draw function we are going to add the following code which will increase the counter and set the position of the line. In the draw method we will need to redraw the background to clear the canvas. Add the following code to the function and place it above everything else within the code block.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">ctx.<span style="color: #660066;">fillStlye</span> <span style="color: #339933;">=</span> “#ffffff”<span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">800</span><span style="color: #339933;">,</span><span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This will clear the previous items on every draw event. Now we can draw the items onto this layer by adding some logic to the draw function and changing the lineTo using the x and y positions.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// redraw the background.</span>
ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> “#ffffff”<span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">800</span><span style="color: #339933;">,</span><span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// increase the counter</span>
counter<span style="color: #339933;">++;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// reset the counter so the line doesn’t get out of hand.</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>counter <span style="color: #339933;">==</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
counter <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Stroke the line.</span>
ctx.<span style="color: #660066;">strokeStyle</span> <span style="color: #339933;">=</span> “#<span style="color: #CC0000;">333333</span>”<span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">beginPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span>posX<span style="color: #339933;">,</span>posY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span>posX <span style="color: #339933;">+</span> counter<span style="color: #339933;">,</span> posY <span style="color: #339933;">+</span> counter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">stroke</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You will now have a moving line on the canvas that will reset every 100 updates.</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=611&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/' rel='bookmark' title='An Introduction to the Canvas'>An Introduction to the Canvas</a></li>
<li><a href='http://codewithdesign.com/2011/05/19/javascript-settimeout-firing-immediately/' rel='bookmark' title='JavaScript: setTimeout Firing Immediately'>JavaScript: setTimeout Firing Immediately</a></li>
<li><a href='http://codewithdesign.com/2009/10/08/javascript-hoirzontal-menu/' rel='bookmark' title='Javascript Hoirzontal Menu'>Javascript Hoirzontal Menu</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to the Canvas</title>
		<link>http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/</link>
		<comments>http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/#comments</comments>
		<pubDate>Tue, 08 May 2012 15:09:48 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[introduction]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=607</guid>
		<description><![CDATA[Before we get started we are going to need to setup our coding environment. This will be a quick and dirty copy paste solution for you. We need two files. The first will be index.html and the second file will be: main.js Fill the index.html file with the following code&#8230; 1 2 3 4 5 [...]
Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/' rel='bookmark' title='Javascript Canvas: Basic Game Logic and Movement'>Javascript Canvas: Basic Game Logic and Movement</a></li>
<li><a href='http://codewithdesign.com/2012/05/11/javascript-arrays/' rel='bookmark' title='Javascript Arrays'>Javascript Arrays</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/"></g:plusone></div><p>Before we get started we are going to need to setup our coding environment. This will be a quick and dirty copy paste solution for you.</p>
<p>We need two files. The first will be index.html and the second file will be: main.js Fill the index.html file with the following code&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE HTML5<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;main.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Caleb Jonasson Canvas Demo<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body <span style="color: #000066;">onload</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;onLoad()&quot;</span> style<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;margin:0px; padding:0px;&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>canvas id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;canvas&quot;</span> width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;800&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;400&quot;</span><span style="color: #339933;">&gt;&lt;/</span>canvas<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Now paste this code into the main.js file. The two files should be placed in the same directory.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066;">onLoad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Get the context from the canvas</span>
ctx <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;canvas&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Add an event listener</span>
document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> registerInteraction<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> registerInteraction <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> window.<span style="color: #660066;">event</span>.<span style="color: #660066;">pageX</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> window.<span style="color: #660066;">event</span>.<span style="color: #660066;">pageY</span><span style="color: #339933;">;</span>
log<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;clicked: x&quot;</span><span style="color: #339933;">+</span>x<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;, y&quot;</span><span style="color: #339933;">+</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> log<span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Using the Context</h3>
<p>You will notice that in the onLoad function we are getting the context of the canvas from the page. This ctx value will allow us to draw on the canvas. The common variable for the context is either &#8220;ctx&#8221; or &#8220;context&#8221;. This value is declared at the top of the document and will be public for everything to use.</p>
<p>We are going to start this lesson by drawing a background onto the canvas so we know where it starts and ends. Add the following code to the onLoad function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#94B73E&quot;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">800</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The fill style is a variable sets the fill color of the item. The fillRect function simply fill a rectangle. The first two parameters are the x and y coordinates of where you would like to start drawing the rectangle. The second parameters are the ending coordinates of the rectangle. Upon running the script you will notice that we now have a solid background.</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=607&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/' rel='bookmark' title='Javascript Canvas: Basic Game Logic and Movement'>Javascript Canvas: Basic Game Logic and Movement</a></li>
<li><a href='http://codewithdesign.com/2012/05/11/javascript-arrays/' rel='bookmark' title='Javascript Arrays'>Javascript Arrays</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/05/08/an-introduction-to-the-canvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorry About The Ads</title>
		<link>http://codewithdesign.com/2012/05/08/sorry-about-the-ads/</link>
		<comments>http://codewithdesign.com/2012/05/08/sorry-about-the-ads/#comments</comments>
		<pubDate>Tue, 08 May 2012 07:06:00 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[Random Posting]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=605</guid>
		<description><![CDATA[I&#8217;ve been getting a lot more traffic lately and therefor I have added two advertisement spots on the site. I know this is a pain but it does help pay for hosting and it isn&#8217;t very intrusive. The ads I have picked will just be images that do not expand or make sounds. Once again, [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/05/08/sorry-about-the-ads/"></g:plusone></div><p>I&#8217;ve been getting a lot more traffic lately and therefor I have added two advertisement spots on the site. I know this is a pain but it does help pay for hosting and it isn&#8217;t very intrusive. The ads I have picked will just be images that do not expand or make sounds.</p>
<p>Once again, my apologies, it helps though.</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=605&type=feed" alt="" /><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/05/08/sorry-about-the-ads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sum3 Project Update</title>
		<link>http://codewithdesign.com/2012/05/03/sum3-project-update/</link>
		<comments>http://codewithdesign.com/2012/05/03/sum3-project-update/#comments</comments>
		<pubDate>Thu, 03 May 2012 15:11:36 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[sum3]]></category>
		<category><![CDATA[sumsumsum]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=601</guid>
		<description><![CDATA[Sum3 progress has been rather slow and not as much content has been posted as I would have liked. A solution to this is to promote the project to students but that seems rather impractical for such a small and featureless project. The other evening I decided to start working on canvas tutorials and write proper [...]
Related posts:<ol>
<li><a href='http://codewithdesign.com/2011/09/15/project-mobileproject-update-blog/' rel='bookmark' title='Project: Mobile/Project Update Blog'>Project: Mobile/Project Update Blog</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/05/03/sum3-project-update/"></g:plusone></div><p>Sum3 progress has been rather slow and not as much content has been posted as I would have liked. A solution to this is to promote the project to students but that seems rather impractical for such a small and featureless project.</p>
<p>The other evening I decided to start working on canvas tutorials and write proper tutorials rather than lessons involving the steps required to make a game. The basic theory behind frames, object handling, collision, logic and mathematics will be some of the items included in the process.</p>
<p>Even though I have been on a bit of a php data mining and javascript game development kick over the last year, I would still like to get back into writing some c++ tutorials since it is one of the most useful languages that you can learn these days providing you want to be an engineer and a diverse one at that.</p>
<p>More information on side projects can be at <a title="Cjonasson html5, android and project blog" href="http://cjonasson.com" target="_blank">http://cjonasson.com</a></p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=601&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2011/09/15/project-mobileproject-update-blog/' rel='bookmark' title='Project: Mobile/Project Update Blog'>Project: Mobile/Project Update Blog</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/05/03/sum3-project-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Decrease Javascript Load Times and Increase Script Speed</title>
		<link>http://codewithdesign.com/2012/05/01/decrease-javascript-load-times-and-increase-script-speed/</link>
		<comments>http://codewithdesign.com/2012/05/01/decrease-javascript-load-times-and-increase-script-speed/#comments</comments>
		<pubDate>Wed, 02 May 2012 05:36:59 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[unit tests]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=598</guid>
		<description><![CDATA[Javascript is not the fastest of languages but it is one of the most adaptable and dynamic of languages. Because the script runs at run time there is no single compiled code base there for there is going to be some overhead assuming you are coding with industry standards. Compression One of the best ways [...]
Related posts:<ol>
<li><a href='http://codewithdesign.com/2010/05/05/remove-images-and-increase-load-times-with-css3/' rel='bookmark' title='Remove images and increase load times with CSS3'>Remove images and increase load times with CSS3</a></li>
<li><a href='http://codewithdesign.com/2012/05/11/javascript-arrays/' rel='bookmark' title='Javascript Arrays'>Javascript Arrays</a></li>
<li><a href='http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/' rel='bookmark' title='Javascript Canvas: Basic Game Logic and Movement'>Javascript Canvas: Basic Game Logic and Movement</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2012/05/01/decrease-javascript-load-times-and-increase-script-speed/"></g:plusone></div><p>Javascript is not the fastest of languages but it is one of the most adaptable and dynamic of languages. Because the script runs at run time there is no single compiled code base there for there is going to be some overhead assuming you are coding with industry standards.</p>
<h2>Compression</h2>
<p>One of the best ways to increase javascript efficiency that requires almost no time at all is to add all of your scripts into one file. Not only will this only send one request to the server it will allow you to compress all of the contents and greatly decrease the through the wire size of the content. (pending on your server zip settings) Compressing code will remove everything that is not required to run the script such as white space and comments. Compressing the code in this way will also change the names of variables and functions to shorten the file as much as possible.</p>
<p>Here is an excellent application created by google that will allow you to compress the javascript file. <a title="closure-compiler" href="http://closure-compiler.appspot.com/home">http://closure-compiler.appspot.com/home </a></p>
<h2>Efficiency</h2>
<p>Another way to greatly improve efficiency within a js file is to decrease repeated operations as much as possible. This consists of optimizing object handlers and adding dynamic event listeners in larger applications. Should you be using set interval it is a good idea to lessen the amount of times that the value is refreshed by. An animation of ui elements do not require a high frame rate to seem impressive.</p>
<h2>Profiling and Debugging</h2>
<p>Many developers like to use an application called <a title="firebug" href="http://getfirebug.com/javascript">FireBug</a>. I prefer to use the built in utilities that come along with <a href="https://www.google.com/chrome">Google Chrome</a>. Both of these options allow profiling and debugging options for your javascript application along with a console that allows you to trace methods and objects within your development process.</p>
<h2>Unit Testing</h2>
<p>The final thing that I would like to mention for those using javascript at home or in the office is that they should use unit tests to make sure that their code is solid and stable. There is a full set of how you can use <a title="JsUnit" href="http://www.jsunit.net/">JsUnit to tests here</a>.</p>
<p>&nbsp;</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=598&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2010/05/05/remove-images-and-increase-load-times-with-css3/' rel='bookmark' title='Remove images and increase load times with CSS3'>Remove images and increase load times with CSS3</a></li>
<li><a href='http://codewithdesign.com/2012/05/11/javascript-arrays/' rel='bookmark' title='Javascript Arrays'>Javascript Arrays</a></li>
<li><a href='http://codewithdesign.com/2012/05/09/javascript-canvas-basic-game-logic-and-movement/' rel='bookmark' title='Javascript Canvas: Basic Game Logic and Movement'>Javascript Canvas: Basic Game Logic and Movement</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2012/05/01/decrease-javascript-load-times-and-increase-script-speed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project: Mobile/Project Update Blog</title>
		<link>http://codewithdesign.com/2011/09/15/project-mobileproject-update-blog/</link>
		<comments>http://codewithdesign.com/2011/09/15/project-mobileproject-update-blog/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 13:50:15 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=587</guid>
		<description><![CDATA[I have been moving my attention towards mobile development recently but I will still be doing the standard web development stuff here. I would like to split up the two and make this site more focussed towards tutorials and articles pertaining to code, design (not graphics) and all that fun stuff. If you would like [...]
Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/03/sum3-project-update/' rel='bookmark' title='Sum3 Project Update'>Sum3 Project Update</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2011/09/15/project-mobileproject-update-blog/"></g:plusone></div><p>I have been moving my attention towards mobile development recently but I will still be doing the standard web development stuff here. I would like to split up the two and make this site more focussed towards tutorials and articles pertaining to code, design (not graphics) and all that fun stuff.</p>
<p>If you would like to check out some of the stuff going on at the other website you can visit it here. http://cjonasson.com</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=587&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://codewithdesign.com/2012/05/03/sum3-project-update/' rel='bookmark' title='Sum3 Project Update'>Sum3 Project Update</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2011/09/15/project-mobileproject-update-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dream In Code User Widget</title>
		<link>http://codewithdesign.com/2011/08/17/dream-in-code-user-widget/</link>
		<comments>http://codewithdesign.com/2011/08/17/dream-in-code-user-widget/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 04:35:08 +0000</pubDate>
		<dc:creator>Caleb Jonasson</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[dreamincode]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://codewithdesign.com/?p=578</guid>
		<description><![CDATA[Recently I pulled an all nighter and coded a user widget using the Dream In Code API. The project is currently unfinished but it is very usable. The idea of the project is to allow the users of dream in code to show off their reputation, posts and group on their website, blog, etc. It [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone size="tall" href="http://codewithdesign.com/2011/08/17/dream-in-code-user-widget/"></g:plusone></div><p>Recently I pulled an all nighter and coded a user widget using the Dream In Code API. The project is currently unfinished but it is very usable. The idea of the project is to allow the users of dream in code to show off their reputation, posts and group on their website, blog, etc. It also gives users the ability to support and promote Dream In Code and the community behind it.</p>
<p>The code for the user widget is as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;iframe
    scrolling=&quot;no&quot;
    style=&quot;width: 282px;
        height: 76px;
        border: none;&quot;
    src=&quot;http://atomicbucket.com/dreamincode/?id=175017&quot;
&gt;&lt;/iframe&gt;</pre></td></tr></table></div>

<p>Once the code has been added to a website it will look as follows:<br />
<img src="http://atomicbucket.com/dreamincode/example.png" alt="Dream In Code User Widget" /><br />
In order to get your own widget you must:<br />
A) become a member of dream in code.<br />
B) Take the id in your user profile and insert it into the id that is within the embed code&#8217;s url.</p>
<p><strong>Note:</strong> There will be additions to this project regarding options for sizes that the widget can come in.</p>
<img src="http://codewithdesign.com/?ak_action=api_record_view&id=578&type=feed" alt="" /><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://codewithdesign.com/2011/08/17/dream-in-code-user-widget/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
