<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>ClickPopMedia</title>
	
	<link>http://www.clickpopmedia.com</link>
	<description>ClickPopMedia is a great little design and illustration firm.</description>
	<pubDate>Fri, 18 Jul 2008 21:12:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/clickpopmedia" type="application/rss+xml" /><item>
		<title>Free Textures from the UK</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/338671675/</link>
		<comments>http://www.clickpopmedia.com/2008/07/17/free-photoshop-textures-from-the-uk/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 00:56:05 +0000</pubDate>
		<dc:creator>Weese</dc:creator>
		
		<category><![CDATA[Download]]></category>

		<category><![CDATA[Free]]></category>

		<category><![CDATA[Textures]]></category>

		<category><![CDATA[Weese]]></category>

		<category><![CDATA[photoshop]]></category>

		<category><![CDATA[Add new tag]]></category>

		<category><![CDATA[Carpet Textures]]></category>

		<category><![CDATA[Flower Print Textures]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=360</guid>
		<description><![CDATA[Sound Foam, Wicker, Carpet, Flower Wallpaper, Paintbrush Stroke and many more!


In the pursuit to keep [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Sound Foam, Wicker, Carpet, Flower Wallpaper, Paintbrush Stroke and many more!</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/07/texture_panel1.jpg"><img class="size-full wp-image-362 aligncenter" title="texture_panel1" src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/texture_panel1.jpg" alt="" width="500" height="375" /></a></p>
<p style="text-align: left;">
<p style="text-align: left;">In the pursuit to keep things fresh with our photo editing, <a href="http://www.clickpopmedia.com/author/vq/" target="_blank">VQ</a> and I are trying to regularly capture new Photoshop Textures wherever we are in the world.  For the next few weeks, I&#8217;ll be in England, so these textures are straight from the UK to you, with love.  I hope you find them useful in your designs!</p>
<p style="text-align: left;">God bless you guys,</p>
<p style="text-align: left;">Weese</p>
<p style="text-align: left;">P.S.- If you&#8217;re looking for some free brick textures, download them <a href="http://www.clickpopmedia.com/2008/06/02/free-brick-textures/" target="_blank">here</a>!</p>
<p style="text-align: left;"><span id="more-360"></span></p>
<p style="text-align: left;"><strong>Floral</strong> pattern:</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/Freebies/textures/UK/floral.jpg"><img class="alignnone size-full wp-image-363" title="Floral Texture" src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/floral_sm.jpg" alt="" width="450" height="300" /></a></p>
<p style="text-align: left;"><strong>Rock</strong></p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/Freebies/textures/UK/rock.jpg"><img class="alignnone size-full wp-image-364" title="Rock Texture" src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/rock_sm.jpg" alt="" width="450" height="300" /></a></p>
<p style="text-align: left;"><strong>Sound </strong>Foam</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/Freebies/textures/UK/soundfoam.jpg"><img class="alignnone size-full wp-image-366" title="Sound Foam Texture" src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/soundfoam_sm.jpg" alt="" width="450" height="300" /></a></p>
<p style="text-align: left;"><strong>Woven </strong>Material</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/Freebies/textures/UK/woven.jpg"><img class="alignnone size-full wp-image-367" title="Woven Texture" src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/woven_sm.jpg" alt="" width="450" height="300" /></a></p>
<p style="text-align: center;"><strong><a href="http://www.clickpopmedia.com/Freebies/textures/uk_textures.zip">Download the UK Textures (.jpg&#8217;s)</a></strong></p>
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/06/24/how-to-make-a-spraypaint-panel/" title="How To Make A Spraypaint Panel">How To Make A Spraypaint Panel (1)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/06/18/water-buffalo-skull-vector/" title="Water Buffalo Skull Vector">Water Buffalo Skull Vector (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/05/02/free-vectors-messy-swirls/" title="Free Vectors: Messy Swirls">Free Vectors: Messy Swirls (3)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/04/10/free-vector-laurels/" title="Free Vector - Laurels">Free Vector - Laurels (4)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/07/17/free-photoshop-textures-from-the-uk/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/07/17/free-photoshop-textures-from-the-uk/</feedburner:origLink></item>
		<item>
		<title>A Vector Bird Wing</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/334230951/</link>
		<comments>http://www.clickpopmedia.com/2008/07/10/a-vector-bird-wing/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 19:05:27 +0000</pubDate>
		<dc:creator>VQ</dc:creator>
		
		<category><![CDATA[Download]]></category>

		<category><![CDATA[Free]]></category>

		<category><![CDATA[Products]]></category>

		<category><![CDATA[VQ]]></category>

		<category><![CDATA[Vector]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=358</guid>
		<description><![CDATA[
Last month was a really heavy month of work for us, and as a result [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/clickpopwings.jpg" alt="" /></p>
<p>Last month was a really heavy month of work for us, and as a result you may have noticed that we weren&#8217;t posting as often. Thankfully, that&#8217;s all about to change (hopefully not the work load, just the fact that one way or the other we&#8217;ll be posting more often).</p>
<p>To kick things off, we have a very useful vector bird wing.</p>
<p>As always, let us know if you do anything neat with it. Have fun, friends.</p>
<p style="text-align: center;"><strong><a href="http://www.clickpopmedia.com/Freebies/wings.zip">Download the Wing Vectors</a></strong></p>
<p><strong>GodBless:VQ</strong><br />
<h3>Other Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/03/13/its-vector-time-again-recording-pack/" title="It&#8217;s Vector Time Again: Recording Pack">It&#8217;s Vector Time Again: Recording Pack (4)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/06/05/a-cssjavascript-horizontal-accordion/" title="A CSS/JavaScript HORIZONTAL Accordion">A CSS/JavaScript HORIZONTAL Accordion (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/04/10/free-vector-laurels/" title="Free Vector - Laurels">Free Vector - Laurels (4)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/" title="Collision Detection and Game Design">Collision Detection and Game Design (0)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/07/10/a-vector-bird-wing/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/07/10/a-vector-bird-wing/</feedburner:origLink></item>
		<item>
		<title>Collision Detection and Game Design</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/334230953/</link>
		<comments>http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 23:58:21 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Paul]]></category>

		<category><![CDATA[Tutorials]]></category>

		<category><![CDATA[Asteroids]]></category>

		<category><![CDATA[Collision Detection]]></category>

		<category><![CDATA[Game Development]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=353</guid>
		<description><![CDATA[

This is the second step in my series of tutorial, the first being Easy Keyboard [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.clickpopmedia.com/wp-content/uploads/2008/07/asteroids.swf" /><embed type="application/x-shockwave-flash" width="550" height="400" src="http://www.clickpopmedia.com/wp-content/uploads/2008/07/asteroids.swf"></embed></object></p>
<p style="text-align: left;">
This is the second step in my series of tutorial, the first being <a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">Easy Keyboard Controls and Game Design</a>. In this tutorial I will be building on what we already have, adding asteroids and the ability to crash into them.<br />
<span id="more-353"></span>I&#8217;ve made a few minor changes to the original code and graphics since the last tutorial, but nothing big.</p>
<p>So I create a MovieClip with 3 frames and a different asteroid shape on each frame (you could have more or less if you wanted).  I give the asteroids their own class since each is going to have to move independently.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">public</span> <span class="kw3">static</span> const LARGE:<span class="kw3">String</span> = <span class="st0">&quot;large&quot;</span>;<br />
<span class="kw3">public</span> <span class="kw3">static</span> const MEDIUM:<span class="kw3">String</span> = <span class="st0">&quot;medium&quot;</span>;<br />
<span class="kw3">public</span> <span class="kw3">static</span> const SMALL:<span class="kw3">String</span> = <span class="st0">&quot;small&quot;</span>;</p>
<p><span class="kw3">public</span> <span class="kw2">var</span> speedX:<span class="kw3">Number</span>;<br />
<span class="kw3">public</span> <span class="kw2">var</span> speedY:<span class="kw3">Number</span>;<br />
<span class="kw3">public</span> <span class="kw2">var</span> <span class="kw3">size</span>:<span class="kw3">String</span>;<br />
&#8230;<br />
<span class="kw3">public</span> <span class="kw2">function</span> Move<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">x</span> += speedX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">y</span> += speedY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">x</span> &gt; <span class="nu0">550</span> + <span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">x</span> = -<span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">x</span> &lt; -<span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">x</span> = <span class="nu0">550</span> + <span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">y</span> &gt; <span class="nu0">400</span> + <span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">y</span> = -<span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">y</span> &lt; -<span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw3">this</span>.<span class="me1">y</span> = <span class="nu0">400</span> + <span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span>;<br />
<span class="br0">&#125;</span></div>
<p>What I&#8217;ve done here is give my Asteroid class X and Y speed properties that work with the <strong>Move()</strong> method for motion.  I intend to call the <strong>Move()</strong> method for each asteroid in the <strong>MainLoop()</strong> function.</p>
<p>On creation (in the constructor) I want to know if this asteroid is actually a piece of a larger asteroid or not.  If it is I&#8217;m going to be passing it the base asteroid that this one is breaking off of to use it&#8217;s X:Y coordinates and speed, plus to know what size to make the new asteroid.</p>
<p>Now back to the <strong>Main</strong> class (in the <a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">last tutorial</a> I called this the <strong>Asteroids</strong> class but changed it to <strong>Main</strong> since I wanted an <strong>Asteroid</strong> class).</p>
<p>We need to keep track of our asteroids.  To do that we will use an <strong>Array</strong>.  We will add this to the <strong>Main</strong> constructor:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">public</span> <span class="kw2">function</span> Main<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dCount = <span class="nu0">0</span>;<br />
&#8230;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">refresh_tf</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_UP</span>, resetGame<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; asteroids = <span class="kw2">new</span> <span class="kw3">Array</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i:<span class="kw3">int</span> = <span class="nu0">0</span>; i&lt;<span class="nu0">6</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw2">new</span> Asteroid<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">stage</span>.<span class="me1">addChild</span><span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>This is just adding 6 asteroids to the stage and giving a click event to a reset button I decided to add.<br />
<strong>dCount</strong> stands for Death Count with an obvious purpose.</p>
<p>The <strong>resetGame()</strong> function is just resetting all the properties to the default.  I still have to make sure to remove all the asteroids before adding all new ones, but that&#8217;s it.</p>
<p>I moved the contents of the <strong>MainLoop()</strong> from the <a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">previous tutorial</a> into a function called <strong>shipControl()</strong> which is now being called from the new <strong>MainLoop()</strong>;</p>
<p>Our revised <strong>MainLoop()</strong> method is as follows:</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">function</span> MainLoop<span class="br0">&#40;</span><span class="kw3">e</span>:TimerEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i <span class="kw1">in</span> asteroids<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">Move</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>dead<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deathTime&#8211;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>deathTime &lt;=<span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dead = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincibleTime = <span class="nu0">150</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincible = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>ship_mc<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipControl<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>!invincible<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; collisionCheck<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">currentTarget</span>.<span class="me1">currentCount</span>%<span class="nu0">10</span> == <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">visible</span> = <span class="br0">&#40;</span>ship_mc.<span class="kw3">visible</span><span class="br0">&#41;</span>? <span class="kw2">false</span>: <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincibleTime&#8211;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>invincibleTime &lt;= <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">visible</span> = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invincible = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>These nested <strong>if..else</strong> statements are here to handle death and resurrection (RIGHT ON!).</p>
<p>So we have our asteroids flying about the screen, but we have yet to make them destroy your ship.  You should notice above the call for to a method call <strong>collisionCheck()</strong>;<br />
Here is that function now:</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">function</span> collisionCheck<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p1:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p1</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p1</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p1 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p1<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p2:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p2</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p2</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p2 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p2<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p3:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p3</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p3</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p3 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p3<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p4:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p4</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p4</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p4 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p4<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> p5:Point = <span class="kw2">new</span> Point<span class="br0">&#40;</span>ship_mc.<span class="me1">p5</span>.<span class="me1">x</span>, ship_mc.<span class="me1">p5</span>.<span class="me1">y</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; p5 = ship_mc.<span class="kw3">localToGlobal</span><span class="br0">&#40;</span>p5<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i <span class="kw1">in</span> asteroids<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p1.<span class="me1">x</span>, p1.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p2.<span class="me1">x</span>, p2.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p3.<span class="me1">x</span>, p3.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p4.<span class="me1">x</span>, p4.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span> ||<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroids<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">hitTestPoint</span><span class="br0">&#40;</span>p5.<span class="me1">x</span>, p5.<span class="me1">y</span>, <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span> &amp;amp;&amp;amp; !dead<span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destroyShip<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; remove<span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Each asteroid does a <strong>hitTest</strong> with each point on my <strong>ship_mc</strong>.  It&#8217;s important that I&#8217;m using <strong>hitTestPoint()</strong> here because it is capable of checking based on the actual shape of the movie clip.  A regular <strong>hitTest</strong> between two <strong>MovieClips</strong> will only check to see if the bounding boxes are overlapping&#8230;  in our case that could still be quite 20 pixels or more away from an actual collision.  This is exactly what makes realistic 2D physics so difficult in ActionScript.</p>
<p>Anyways, the Hit Test may be a little buggy in some cases, but <strong>hitTestPoint</strong> works pretty well for us here.  After we detect a hit of course we have to destroy the ship and asteroid and set the death timer.  the <strong>destroyShip()</strong> function is trivial enough, but I would like to take a quick look at a line from the remove() method:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">stage</span>.<span class="me1">addChild</span><span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>asteroids.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw2">new</span> Asteroid<span class="br0">&#40;</span>asteroids<span class="br0">&#91;</span>num<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
<p>I really just need to explain how this slightly complicated jumble works.  Reading this from the inner most parenthases out;</p>
<p>We are creating a new Asteroid object (passing it our parent asteroid that has just been destroyed).<br />
<strong>new Asteroid(asteroids[num])</strong></p>
<p>We add that Asteroid object to the end of our asteroids Array which is returning the new length of the Array.<br />
<strong>asteroids.push(&#8230;)</strong></p>
<p>We then use that new length (minus 1) to add our newest asteroid to the stage.<br />
<strong>stage.addChild(asteroids[...-1]);</strong></p>
<p>Eh, see now?  Collision detection is easy!  I think my next installment might be a little more interesting when I add levels, lives, and a scoring system.</p>
<p>&#8230;  No bullets you ask?  Well that&#8217;s just an extension of what I&#8217;ve already written here right?  The only extra thing you have to remember is that the bullets have a limited lifespan.</p>
<p>If you are still confused and can&#8217;t do it on your own (if you want to <em>learn</em> you really aught to at least try) then you can always check out the finished source when it&#8217;s released.</p>
<p>The source code for the example in this tutorial can be found here: <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/07/asteroidsv2source.rar">Asteroids - V2 Source</a></p>
<p><a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/">&lt; Lesson 1: Easy Keyboard Controls and Game Design</a><br />
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/" title="Easy Keyboard Controls and Game Design">Easy Keyboard Controls and Game Design (3)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/</feedburner:origLink></item>
		<item>
		<title>Free Vector Octopus</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/327465060/</link>
		<comments>http://www.clickpopmedia.com/2008/06/26/free-vector-octopus/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 02:10:53 +0000</pubDate>
		<dc:creator>VQ</dc:creator>
		
		<category><![CDATA[Download]]></category>

		<category><![CDATA[Free]]></category>

		<category><![CDATA[Products]]></category>

		<category><![CDATA[VQ]]></category>

		<category><![CDATA[Vector]]></category>

		<category><![CDATA[cartoon]]></category>

		<category><![CDATA[freebie]]></category>

		<category><![CDATA[octopus]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=351</guid>
		<description><![CDATA[
Today is your luck day, friend. It&#8217;s free octopus day at ClickPopMedia! So step up [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/header1.jpg" alt="" /></p>
<p style="text-align: left;">Today is your luck day, friend. It&#8217;s free octopus day at ClickPopMedia! So step up and download yourself an octopus.</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/Freebies/octopus.zip"><strong>Download the Vector Octopus (.ai and .eps)</strong></a></p>
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/05/09/free-vector-platypus-swimmer/" title="Free Vector: Platypus Swimmer">Free Vector: Platypus Swimmer (1)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/04/21/free-vectors-speech-bubbles/" title="Free Vectors: Speech Bubbles">Free Vectors: Speech Bubbles (4)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/06/18/water-buffalo-skull-vector/" title="Water Buffalo Skull Vector">Water Buffalo Skull Vector (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/06/05/batik-is-beautiful/" title="Batik is Beautiful - Free Vector Swatches UPDATED">Batik is Beautiful - Free Vector Swatches UPDATED (17)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/26/free-vector-octopus/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/06/26/free-vector-octopus/</feedburner:origLink></item>
		<item>
		<title>Easy Keyboard Controls and Game Design</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/327465061/</link>
		<comments>http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 01:21:07 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Paul]]></category>

		<category><![CDATA[Tutorials]]></category>

		<category><![CDATA[Asteroids]]></category>

		<category><![CDATA[Game Development]]></category>

		<category><![CDATA[Keyboard]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=340</guid>
		<description><![CDATA[
In this tutorial I will be going over some of the basic elements to making [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.clickpopmedia.com/wp-content/uploads/2008/06/asteroids.swf" /><embed type="application/x-shockwave-flash" width="550" height="400" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/asteroids.swf"></embed></object><br />
In this tutorial I will be going over some of the basic elements to making a game in Flash. This being the first in a short series of tutorials on the subject, I will cover the main game loop and keyboard controls.<br />
<span id="more-340"></span><br />
First off we need to set up some simple graphics.  I did some REALLY simple graphics as you can see.  The <strong>ship_mc</strong> being just a triangle and on the 3rd frame of the ship movie clip it get&#8217;s a little fire tail.  Since I am just imitating <em>Atari Interactive, Inc.</em>&#8217;s<em> Asteroids</em>, we don&#8217;t really need anything more then that for now.<br />
Now, to get our initial code setup:</p>
<div class="dean_ch" style="white-space: wrap;">package <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="kw3">text</span>.<span class="me1">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="me1">Timer</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Asteroids <span class="kw3">extends</span> <span class="kw3">MovieClip</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> mainTimer:Timer;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Asteroids<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer = <span class="kw2">new</span> Timer<span class="br0">&#40;</span><span class="nu0">20</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TimerEvent.<span class="me1">TIMER</span>, MainLoop<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">DEACTIVATE</span>, deactive<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">ACTIVATE</span>, active<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">stage</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>KeyboardEvent.<span class="me1">KEY_DOWN</span>, kDown<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">stage</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>KeyboardEvent.<span class="me1">KEY_UP</span>, kUp<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> MainLoop<span class="br0">&#40;</span><span class="kw3">e</span>:TimerEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> deactive<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> active<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTimer.<span class="kw3">start</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> kDown<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">function</span> kUp<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>So far this is just a skeleton of our game.  We have our <strong>KEY_DOWN</strong> and <strong>KEY_UP</strong> events which will handle all of our keyboard controls later.  But, more importantly, we have our <strong>mainTimer</strong>.  By setting up our game engine to run based on a timer I can later change the frame rate without changing the game dynamics (I left the frame rate at 12/sec for the example above).  This is also useful if your game has too many graphical elements and the frame rate drops on some machines, this will preserve the speed of the game itself.<br />
So, please notice that I have the Timer set to &#8220;tick&#8221; every 20 milliseconds (1000 milliseconds to 1 seconds) which is about 50 ticks per second. Because of that, we are going to have some small values to work with when playing with flight speed and rotation in our ship.<br />
But, first let us think about keyboard controls:</p>
<div class="dean_ch" style="white-space: wrap;">protected <span class="kw2">var</span> thrust:<span class="kw3">Boolean</span>;<br />
protected <span class="kw2">var</span> rpm:<span class="kw3">Number</span>;<br />
protected <span class="kw2">function</span> kDown<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
<span class="co1">//&nbsp; &nbsp; &nbsp; trace(e.keyCode);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">37</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">65</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">100</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">-4</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;LEFT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">38</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">87</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">104</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thrust = <span class="kw2">true</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;UP&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">39</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">68</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">102</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">4</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;RIGHT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
protected <span class="kw2">function</span> kUp<span class="br0">&#40;</span><span class="kw3">e</span>:KeyboardEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">37</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">65</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">100</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">0</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;LEFT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">38</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">87</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">104</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thrust = <span class="kw2">false</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;UP&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">39</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">68</span> || <span class="kw3">e</span>.<span class="me1">keyCode</span> == <span class="nu0">102</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">0</span>;<br />
<span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;RIGHT&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p><strong>rpm</strong> and <strong>thrust</strong> are going to control our ships flight in the <strong>MainLoop</strong> later.  The <strong>keyCode</strong> is a number which represents the key being pressed or released on the keyboard.  I prefer to set a value on down because the <strong>KEY_DOWN</strong> event will be fired off numerous times very quickly if the key is held too long.  I have the controls set up to work with WASD, the arrow keys, or the num pad.<br />
To find the key values I just traced <strong>e.keyCode</strong> in the <strong>kUp()</strong> function and tried pressing the keys in question.  This got me the numbers you see in the code above.  The commented out traces are there to make sure we have the correct keys, since we don&#8217;t have any other indicator yet.</p>
<p>The next step is a simple one (except for some of the math):</p>
<div class="dean_ch" style="white-space: wrap;">protected const TOP_SPEED:<span class="kw3">Number</span> = <span class="nu0">10</span>;<br />
protected const ACCELERATION:<span class="kw3">Number</span> = .<span class="nu0">1</span>;<br />
protected const FRICTION:<span class="kw3">Number</span> = .<span class="nu0">995</span>;</p>
<p>protected <span class="kw2">var</span> mainTimer:Timer;<br />
protected <span class="kw2">var</span> speedX:<span class="kw3">Number</span>;<br />
protected <span class="kw2">var</span> speedY:<span class="kw3">Number</span>;</p>
<p><span class="kw3">public</span> <span class="kw2">function</span> Asteroids<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rpm = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; speedX = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; speedY = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8230;<br />
<span class="br0">&#125;</span></p>
<p>protected <span class="kw2">function</span> MainLoop<span class="br0">&#40;</span><span class="kw3">e</span>:TimerEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="me1">rotation</span> += rpm;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dx:<span class="kw3">Number</span> = ACCELERATION * <span class="kw3">Math</span>.<span class="kw3">cos</span><span class="br0">&#40;</span><span class="br0">&#40;</span>ship_mc.<span class="me1">rotation*</span><span class="kw3">Math</span>.<span class="kw3">PI</span><span class="br0">&#41;</span>/<span class="nu0">180</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dy:<span class="kw3">Number</span> = ACCELERATION * <span class="kw3">Math</span>.<span class="kw3">sin</span><span class="br0">&#40;</span><span class="br0">&#40;</span>ship_mc.<span class="me1">rotation*</span><span class="kw3">Math</span>.<span class="kw3">PI</span><span class="br0">&#41;</span>/<span class="nu0">180</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>thrust<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedX += dx;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedY += dy;<br />
<span class="co1">//We want to have a max speed in any direction of the compass</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> speed = speedX*speedX + speedY*speedY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>speed &gt;= TOP_SPEED*TOP_SPEED<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedX *= <span class="br0">&#40;</span>TOP_SPEED*TOP_SPEED<span class="br0">&#41;</span>/speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speedY *= <span class="br0">&#40;</span>TOP_SPEED*TOP_SPEED<span class="br0">&#41;</span>/speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">gotoAndStop</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="kw3">gotoAndStop</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="co1">//I know there is no friction in space, but I can&#8217;t remember if Asteroids had it or not.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; speedX *= FRICTION;<br />
&nbsp; &nbsp; &nbsp; &nbsp; speedY *= FRICTION;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="me1">x</span> += speedX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ship_mc.<span class="me1">y</span> += speedY;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">x</span> &gt; <span class="nu0">560</span><span class="br0">&#41;</span> ship_mc.<span class="me1">x</span> = <span class="nu0">-10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">x</span> &lt; <span class="nu0">-10</span><span class="br0">&#41;</span> ship_mc.<span class="me1">x</span> = <span class="nu0">560</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">y</span> &gt; <span class="nu0">410</span><span class="br0">&#41;</span> ship_mc.<span class="me1">y</span> = <span class="nu0">-10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ship_mc.<span class="me1">y</span> &lt; <span class="nu0">-10</span><span class="br0">&#41;</span> ship_mc.<span class="me1">y</span> = <span class="nu0">410</span>;<br />
<span class="br0">&#125;</span></div>
<p>Here we have initialized some variables in the constructor first.  Then we filled in our <strong>MainLoop</strong> to give our spaceship some life.  I would think the <strong>rotation</strong> is self evident&#8230;  it&#8217;s the first line of the method.  I used some constants in my math (<strong>ACCELERATION, TOP_SPEED,</strong> and <strong>FRICTION</strong>) so that I can easily adjust the game settings all in one place, without searching for the parts of the code that I need changed.<br />
The last group of <strong>if</strong> statements above are checking to see in our ship has flown off the screen and if it has it will be moved to the other side.</p>
<p>That&#8217;s all for now.  Next time I will probably add some asteroids and talk a little about <a href="http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/">collision detection</a>.</p>
<p>You can download the source for this example here: <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/asteroidssource.rar">AsteroidsSource.rar</a><br />
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/07/07/collision-detection-and-game-design/" title="Collision Detection and Game Design">Collision Detection and Game Design (0)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/06/25/easy-keyboard-controls-and-game-design/</feedburner:origLink></item>
		<item>
		<title>How To Make A Spraypaint Panel</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/327465062/</link>
		<comments>http://www.clickpopmedia.com/2008/06/24/how-to-make-a-spraypaint-panel/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 20:21:48 +0000</pubDate>
		<dc:creator>Weese</dc:creator>
		
		<category><![CDATA[DIY]]></category>

		<category><![CDATA[Free]]></category>

		<category><![CDATA[Just for Fun!]]></category>

		<category><![CDATA[Paintings]]></category>

		<category><![CDATA[Weese]]></category>

		<category><![CDATA[art]]></category>

		<category><![CDATA[Graffiti Canvas]]></category>

		<category><![CDATA[Pauls Panel]]></category>

		<category><![CDATA[Spraypaint Panels]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=342</guid>
		<description><![CDATA[
So over the past two months I&#8217;ve been painting these Panels of VQ&#8217;s Vectors.  [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/four_panels1.jpg"><img class="size-medium wp-image-349" title="four_panels1" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/four_panels1-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>So over the past two months I&#8217;ve been painting these Panels of VQ&#8217;s <a href="http://www.clickpopmedia.com/this_is_free/" target="_blank">Vectors</a>.  That got the boys and I over at ClickPop talking about how it was time to teach you how to create them too.  It&#8217;s pretty simple, all you&#8217;ll need is:<span id="more-342"></span></p>
<p>-Panel, which can purchased online or at your local arts and craft store (Michaels, A.C. Moore, etc.)</p>
<p>-A can(s) of spray paint</p>
<p>-Black Chisel Tip marker (I prefer Grand &amp; Toy, or Sharpie).</p>
<p>Below is just a shot of my panel.</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step1.jpg"><img class="size-full wp-image-341" title="step1" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step1.jpg" alt="" width="500" height="374" /></a></p>
<p>Next you&#8217;re going to sketch out your drawing with a regular black marker, I used a sharpie for this part.  My inspiration for this panel is from VQ&#8217;s <a href="http://weare.clickpopmedia.com/author/paul/" target="_blank">vector of Paul</a> and his <a href="http://www.clickpopmedia.com/2008/03/20/nuclear-warning-vectors/" target="_blank">Nuclear Warning</a> vector</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step2.jpg"><img class="size-full wp-image-343" title="step2" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step2.jpg" alt="" width="500" height="374" /></a></p>
<p>Next, go over your initial sketch with your Chisel Tipped Marker (Grand &amp; Toy seem to work really well for this).  Make sure your perimeter lines are at least the width of your chisel tip.</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step3.jpg"><img class="size-full wp-image-344" title="step3" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step3.jpg" alt="" width="500" height="374" /></a></p>
<p>Now, grab your can of spray, and work from the outside of the canvas inward.  Your paint is going to start drying before you finish painting the whole canvas, so be looking for any white that might come through.  Be sure to get even lines.  If you spray over your drawing, don&#8217;t worry about it, actually you can get some cool cell-shading effects by going over the lines a little.</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step4.jpg"><img class="size-full wp-image-345" title="step4" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step4.jpg" alt="" width="500" height="374" /></a></p>
<p>Finish spraying the whole canvas.  Let it dry for about 20 minutes (if your location is colder it may take longer).</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step5.jpg"><img class="size-full wp-image-346" title="step5" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/step5.jpg" alt="" width="500" height="374" /></a></p>
<p>Then take your canvas and go over all of your lines again with your Chisel Tipped Marker.</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/100_2178.jpg"><img class="size-full wp-image-348" title="100_2178" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/100_2178.jpg" alt="" width="500" height="375" /></a></p>
<p>And then you&#8217;re done!  Below is all four panels for the ClickPop Office.  If you end up making millions on your panels, be sure to let me know.  Enjoy!  God bless you guys.   -Weese</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/four_panels.jpg"><img class="size-full wp-image-347" title="four_panels" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/four_panels.jpg" alt="" width="500" height="375" /></a></p>
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/04/02/a-good-ideacontinued/" title="A Good Idea&#8230;continued">A Good Idea&#8230;continued (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/07/17/free-photoshop-textures-from-the-uk/" title="Free Textures from the UK">Free Textures from the UK (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/02/26/the-brand-new-super-fantastic-2008-clickpop-lineup-and-a-vector-megaphone/" title="The ClickPopLineup (&#038; a vector megaphone)">The ClickPopLineup (&#038; a vector megaphone) (5)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/24/how-to-make-a-spraypaint-panel/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/06/24/how-to-make-a-spraypaint-panel/</feedburner:origLink></item>
		<item>
		<title>Water Buffalo Skull Vector</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/327465063/</link>
		<comments>http://www.clickpopmedia.com/2008/06/18/water-buffalo-skull-vector/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 15:43:52 +0000</pubDate>
		<dc:creator>VQ</dc:creator>
		
		<category><![CDATA[Download]]></category>

		<category><![CDATA[Free]]></category>

		<category><![CDATA[Products]]></category>

		<category><![CDATA[VQ]]></category>

		<category><![CDATA[Vector]]></category>

		<category><![CDATA[freebies]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=336</guid>
		<description><![CDATA[
Howdy pardners. I&#8217;m glad you stopped by the ol&#8217; ClickPop Ranch. Sit down, rest your [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="alignnone size-full wp-image-337" title="skull" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/skull.png" alt="" width="244" height="300" /></p>
<p>Howdy pardners. I&#8217;m glad you stopped by the ol&#8217; ClickPop Ranch. Sit down, rest your feet a spell, and enjoy this water buffalo skull vector. I realize that this probably isn&#8217;t the way a water buffalo rancher would write. It&#8217;s more like a regular buffalo rancher, but hey, it gets the job done.</p>
<p style="text-align: center;"><a href="http://www.clickpopmedia.com/Freebies/cowskull.zip">Download the Water Buffalo Skull Vector (.ai and .eps)</a></p>
<p style="text-align: left;"><strong>GodBless:VQ</strong></p>
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/04/10/free-vector-laurels/" title="Free Vector - Laurels">Free Vector - Laurels (4)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/06/05/batik-is-beautiful/" title="Batik is Beautiful - Free Vector Swatches UPDATED">Batik is Beautiful - Free Vector Swatches UPDATED (17)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/05/19/free-vectors-penguins/" title="Free Vectors: Penguins!">Free Vectors: Penguins! (3)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/04/21/free-vectors-speech-bubbles/" title="Free Vectors: Speech Bubbles">Free Vectors: Speech Bubbles (4)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/18/water-buffalo-skull-vector/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/06/18/water-buffalo-skull-vector/</feedburner:origLink></item>
		<item>
		<title>Batik Photoshop Patterns</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/310088442/</link>
		<comments>http://www.clickpopmedia.com/2008/06/11/batik-photoshop-patterns/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 02:19:46 +0000</pubDate>
		<dc:creator>VQ</dc:creator>
		
		<category><![CDATA[Download]]></category>

		<category><![CDATA[Free]]></category>

		<category><![CDATA[Products]]></category>

		<category><![CDATA[Textures]]></category>

		<category><![CDATA[VQ]]></category>

		<category><![CDATA[photoshop]]></category>

		<category><![CDATA[batik]]></category>

		<category><![CDATA[fabric]]></category>

		<category><![CDATA[texture]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=334</guid>
		<description><![CDATA[
Last week we gave out some free Batik vectors. In that post, I mentioned that [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img title="Photoshop Batik Pattern" src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/psheader.gif" alt="" /></p>
<p>Last week we gave out some <a href="http://www.clickpopmedia.com/2008/06/05/batik-is-beautiful/">free Batik vectors</a>. In that post, I mentioned that if anyone wanted the patterns as Photoshop patterns, I&#8217;d be glad to share them. Well, you asked, and I&#8217;ve finally come through.</p>
<p>In this pack of Photoshop patterns I have 6 different color schemes ranging from nice to WEIRD. There is a 500px wide and a 250px wide version of each pattern. Have fun my friends! Let us know if you do anything wonderful with them.</p>
<p style="text-align: center;"><strong><a href="http://www.clickpopmedia.com/Freebies/patterns/psBatik.pat">Download the Batik Photoshop Patterns (.pat)</a></strong></p>
<p style="text-align: center;"><strong><a href="http://www.clickpopmedia.com/Freebies/patterns/psBatik.zip">Download the Batik Photoshop Patterns (.png)</a></strong></p>
<p><strong>GodBless:VQ</strong><br />
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/06/05/batik-is-beautiful/" title="Batik is Beautiful - Free Vector Swatches UPDATED">Batik is Beautiful - Free Vector Swatches UPDATED (17)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/06/02/free-brick-textures/" title="Free Brick Textures">Free Brick Textures (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/04/30/photoshop-watercolor-paint-smudges/" title="Photoshop Watercolor Paint Smudges">Photoshop Watercolor Paint Smudges (0)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/11/batik-photoshop-patterns/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/06/11/batik-photoshop-patterns/</feedburner:origLink></item>
		<item>
		<title>Realistic Shadow Effects using Filters</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/309706106/</link>
		<comments>http://www.clickpopmedia.com/2008/06/11/realistic-shadow-effects-using-filters/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 15:37:42 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Paul]]></category>

		<category><![CDATA[Tutorials]]></category>

		<category><![CDATA[DropShadowFilter]]></category>

		<category><![CDATA[Filters]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=329</guid>
		<description><![CDATA[
I have another simple but neat, little tutorial here on Flash CS3 filters.  This [...]]]></description>
			<content:encoded><![CDATA[<pre><center><embed src="http://www.clickpopmedia.com/wp-content/uploads/2008/06/shadows.swf" width="550" height="400" allowscriptaccess="always" allowfullscreen="true"></center></pre>
<p>I have another simple but neat, little tutorial here on Flash CS3 filters.  This time I&#8217;m not using <strong>Tweens</strong> at all.  Our effect is going to use the <strong>MouseEvent.MOUSE_MOVE</strong> event to create the illusion of a light source coming from our cursor.</p>
<p><span id="more-329"></span></p>
<p>To begin with we are going to make our Shadows class.  This class is going to extend <strong>MovieClip</strong>, have a <strong>DropShadowFilter</strong> pre-applied to it and a public method to change the drop shadow filters distance and angle.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">public</span> <span class="kw2">class</span> Shadows <span class="kw3">extends</span> <span class="kw3">MovieClip</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">var</span> All:<span class="kw3">Array</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> txtF:<span class="kw3">TextField</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> drop:DropShadowFilter;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> distance:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> angle:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> dropAlpha:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> blurX:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="kw2">var</span> blurY:<span class="kw3">Number</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Shadows<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>Shadows.<span class="me1">All</span> == <span class="kw2">null</span><span class="br0">&#41;</span> Shadows.<span class="me1">All</span> = <span class="kw2">new</span> <span class="kw3">Array</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dropAlpha = <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurX = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurX = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drop = <span class="kw2">new</span> DropShadowFilter<span class="br0">&#40;</span>distance, angle, <span class="nu0">0</span>, dropAlpha, blurX, blurY<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">filters</span> = <span class="br0">&#91;</span>drop<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shadows.<span class="me1">All</span>.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw3">this</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> lightSource<span class="br0">&#40;</span>X:<span class="kw3">Number</span>, Y:<span class="kw3">Number</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dx:<span class="kw3">Number</span> = <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">x</span> + <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="kw3">width</span>/<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>-X;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dy:<span class="kw3">Number</span> = <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">y</span> + <span class="br0">&#40;</span><span class="kw3">this</span>.<span class="kw3">height</span>/<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>-Y;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle = <span class="br0">&#40;</span><span class="nu0">180</span> * <span class="kw3">Math</span>.<span class="kw3">atan</span><span class="br0">&#40;</span>dy/dx<span class="br0">&#41;</span><span class="br0">&#41;</span> / <span class="kw3">Math</span>.<span class="kw3">PI</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>dx &lt; <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle += <span class="nu0">180</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance = <span class="kw3">Math</span>.<span class="kw3">sqrt</span><span class="br0">&#40;</span>dy*dy + dx*dx<span class="br0">&#41;</span>/<span class="nu0">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dropAlpha = <span class="nu0">10</span>/distance;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurX = <span class="kw3">Math</span>.<span class="kw3">abs</span><span class="br0">&#40;</span>dx/<span class="nu0">20</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blurY = <span class="kw3">Math</span>.<span class="kw3">abs</span><span class="br0">&#40;</span>dy/<span class="nu0">20</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drop = <span class="kw2">new</span> DropShadowFilter<span class="br0">&#40;</span>distance, angle, <span class="nu0">0</span>, dropAlpha, blurX, blurY<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">filters</span> = <span class="br0">&#91;</span>drop<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>I hope  you can see what is going on in the code.  I&#8217;m simply setting all my variables equal to 0 or 1, depending on what it&#8217;s for, and applying my filter in the constructor.  Also note that I&#8217;m saving all my objects in a static array.  This makes it easier to call all the <strong>lightSource()</strong> methods at once in a for loop later.</p>
<p>In the <strong>lightSource()</strong> method we have a little bit of math that you might be unfamiliar with.<br />
My variables <strong>dy</strong> and <strong>dx</strong> stand for distance y or x and I&#8217;m setting them equal to the distance from the point given and the center of my ShadowObject.</p>
<p><strong>angle</strong> is going to be the angle of the drop shadow and it needs to be in degrees.  <strong>Math.atan()</strong> is called arc-tangent in the Trigonometry world and it gives your the value of the angle opposite the Y side of a right triangle in radians.  If that doesn&#8217;t make sense, just know that it&#8217;s giving me that angle I need, but in the wrong units. I convert it by multiplying by 180 and dividing by PI.<strong> Math.atan()</strong> only returns a value between -pi/2 and pi/2 (-90 to 90 degrees) which only covers half a circle, so I have to check if we actually need the other side.  And, that&#8217;s what my if() statement is for.</p>
<p><strong>distance</strong> is calculated using the Pythagorean theorem C^2 = A^2 + B^2 (and then divided by 10 otherwise it&#8217;s just too much).<strong></strong></p>
<p><strong>DropAlpha</strong>, <strong>blurX</strong>, and <strong>blurY</strong> are all set pretty clearly (blur has to be positive, thus the <strong>Math.abs()</strong> or absolute value).</p>
<p>Finally our function creates a new drop filter with our new values and applies it to our Shadow object.</p>
<p>Except for trying to remember the math involved, this one has been pretty easy so far, huh?  Well then, let&#8217;s try using it in a project!</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> str = <span class="kw2">new</span> <span class="kw3">String</span><span class="br0">&#40;</span><span class="st0">&quot;ClickPop&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> str2 = <span class="kw2">new</span> <span class="kw3">String</span><span class="br0">&#40;</span><span class="st0">&quot;Media&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> letter:Shadows;<br />
<span class="kw2">var</span> newX:<span class="kw3">Number</span> = <span class="nu0">30</span>;<br />
<span class="kw2">var</span> overLetter:<span class="kw3">TextField</span>;</p>
<p><span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;str.<span class="kw3">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; letter = <span class="kw2">new</span> Shadows<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">x</span> = newX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">y</span> = <span class="nu0">80</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter = <span class="kw2">new</span> <span class="kw3">TextField</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">text</span> = str.<span class="kw3">charAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">setTextFormat</span><span class="br0">&#40;</span><span class="kw2">new</span> <span class="kw3">TextFormat</span><span class="br0">&#40;</span><span class="st0">&quot;Georgia&quot;</span>, <span class="nu0">100</span>, 0&#215;0000FF, <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">autoSize</span> = TextFieldAutoSize.<span class="kw3">LEFT</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">addChild</span><span class="br0">&#40;</span>overLetter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>letter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; newX += letter.<span class="kw3">width</span>;<br />
<span class="br0">&#125;</span><br />
newX = <span class="nu0">80</span>;<br />
<span class="kw1">for</span><span class="br0">&#40;</span>i=<span class="nu0">0</span>; i&lt;str2.<span class="kw3">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; letter = <span class="kw2">new</span> Shadows<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">x</span> = newX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">y</span> = <span class="nu0">180</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter = <span class="kw2">new</span> <span class="kw3">TextField</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">text</span> = str2.<span class="kw3">charAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">setTextFormat</span><span class="br0">&#40;</span><span class="kw2">new</span> <span class="kw3">TextFormat</span><span class="br0">&#40;</span><span class="st0">&quot;Georgia&quot;</span>, <span class="nu0">100</span>, 0&#215;0000FF, <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overLetter.<span class="kw3">autoSize</span> = TextFieldAutoSize.<span class="kw3">LEFT</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; letter.<span class="me1">addChild</span><span class="br0">&#40;</span>overLetter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>letter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; newX += letter.<span class="kw3">width</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">function</span> changeLight<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;Shadows.<span class="me1">All</span>.<span class="kw3">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shadows.<span class="me1">All</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">lightSource</span><span class="br0">&#40;</span><span class="kw3">stage</span>.<span class="me1">mouseX</span>, <span class="kw3">stage</span>.<span class="me1">mouseY</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw3">stage</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_MOVE</span>, changeLight<span class="br0">&#41;</span>;</div>
<p>So, there it is.  I&#8217;m adding each letter to a different Shadow object so that their shadows move independently.  I then update all the shadow light sources to the mouse&#8217;s X and Y coordinates every time the mouse moves.  SO EASY!!</p>
<p>I have a few more ideas for cool effects that you can make with filters and I will probably post about them soon.</p>
<p>Download the Source Code for the example used in this post here: <a href="http://www.clickpopmedia.com/wp-content/uploads/2008/06/shadows.zip">ShadowsSource.zip</a><br />
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/05/28/cool-rollover-effects-with-filters/" title="Cool Rollover Effects with Filters">Cool Rollover Effects with Filters (6)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/11/realistic-shadow-effects-using-filters/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/06/11/realistic-shadow-effects-using-filters/</feedburner:origLink></item>
		<item>
		<title>A CSS/JavaScript HORIZONTAL Accordion</title>
		<link>http://feeds.feedburner.com/~r/clickpopmedia/~3/305480879/</link>
		<comments>http://www.clickpopmedia.com/2008/06/05/a-cssjavascript-horizontal-accordion/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 17:45:41 +0000</pubDate>
		<dc:creator>§ean</dc:creator>
		
		<category><![CDATA[Sean]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[accordion]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[horizontal]]></category>

		<guid isPermaLink="false">http://www.clickpopmedia.com/?p=328</guid>
		<description><![CDATA[Accordions are great, but sometimes a big pain to setup.  Mootools, and several other [...]]]></description>
			<content:encoded><![CDATA[<p>Accordions are great, but sometimes a big pain to setup.  <a title="MooTools" href="http://www.mootools.net" target="_blank">Mootools</a>, and several other libraries, offer great pre-built accordion systems, but they&#8217;ve got their issues.  We recently tried using mootools accordion on a client&#8217;s website, but we were having a fair amount of browser compatibility problems, so we set out in search for a better solution.  The nice people at <a title="Switch on the Code" href="http://www.switchonthecode.com" target="_blank">Switch on the Code</a> wrote a nice tutorial on how to build your own <a title="Javascript and CSS Tutorial - Accordion Menus" href="http://blog.paranoidferret.com/index.php/2007/10/22/javascript-and-css-tutorial-accordion-menus/" target="_blank">CSS/Javascript accordion</a>.  Needless to say, it suited our needs perfectly. Then I thought to myself, wouldn&#8217;t it be great if someone made a HORIZONTAL accordion using a similar method.</p>
<p><iframe src="http://www.clickpopmedia.com/sean_tutorials/horizontal_accordion/horizontal_accordion.htm" style="width:650px;height:300px;border:none;"></iframe></p>
<p><span id="more-328"></span>Today we are going to do something that is important for any developer, examine code.  The ability to read another person&#8217;s code is vital if you want to be successful.  Obviously everyone does things differently, and it&#8217;s easy to get into thinking that you have to do everything from scratch, but sometimes you are just going to have to use a prebuilt element. As a lesson, we will be taking a look at the Accordion Code from Switch on the Code and turn it in to a horizontal accordion.</p>
<p>We&#8217;ll start first with the HTML</p>
<p>Switch on the Code provides with this:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;AccordionContainer&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionContainer&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">onclick</span>=<span class="st0">&quot;runAccordion(1);&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionTitle&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; Accordion 1<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;Accordion1Content&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionContent&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; I Am Accordion 1.<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">onclick</span>=<span class="st0">&quot;runAccordion(2);&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionTitle&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; Accordion 2<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;Accordion2Content&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionContent&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; I Am Accordion 2.<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">onclick</span>=<span class="st0">&quot;runAccordion(4);&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionTitle&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; Accordion 4<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;Accordion4Content&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionContent&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; I Am Accordion 4.<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">onclick</span>=<span class="st0">&quot;runAccordion(5);&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionTitle&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; Accordion 5<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;Accordion5Content&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;AccordionContent&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; I Am Accordion 5.<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span></div>
<p>This is a bit bulky for my taste, so I will be cutting down on a lot of this.  I will layout an all new structure, and I will also only use 2 accordions instead of 5&#8230; but you can use as many as you want.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&quot;Toggler&quot;</span> <span class="re0">onclick</span>=<span class="st0">&quot;runAccordion(1);&quot;</span><span class="re2">&gt;</span></span><span class="sc3"><span class="re1">&lt;img</span> <span class="re0">src</span>=<span class="st0">&quot;accordion1.png&quot;</span> <span class="re0">alt</span>=<span class="st0">&quot;&quot;</span> <span class="re2">/&gt;</span></span><span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;Content1&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Content&quot;</span><span class="re2">&gt;</span></span>I Am Accordion 1.<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&quot;Toggler&quot;</span> <span class="re0">onclick</span>=<span class="st0">&quot;runAccordion(2);&quot;</span><span class="re2">&gt;</span></span><span class="sc3"><span class="re1">&lt;img</span> <span class="re0">src</span>=<span class="st0">&quot;accordion2.png&quot;</span> <span class="re0">alt</span>=<span class="st0">&quot;&quot;</span> <span class="re2">/&gt;</span></span><span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;Content2&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Content&quot;</span> <span class="re0">style</span>=<span class="st0">&quot;border-right:1px solid #333;&quot;</span><span class="re2">&gt;</span></span>I Am Accordion 2.<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span></div>
<p>There, that&#8217;s better.  I have replaced the multiple divs per section with just 2 divs for each accordion section.  There is a Toggler and a Content div.  Each div is assigned the appropriate class.  Togglers are given an onclick function of runAccordion(#), where the # is replaced by the section number.  Content divs are given and id of Content# using the same principle.  You will also notice the last section is given some extra style features, this is so there will be an end border on the entire Accordion.</p>
<p>Next we&#8217;ll move on to the CSS.  We&#8217;re going to completely scrap everything they gave us, and start from scratch:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="re1">.Toggler</span><br />
<span class="br0">&#123;</span><br />
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;width<span class="re2">:<span class="re3">20px</span></span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; height<span class="re2">:<span class="re3">200px</span></span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; overflow<span class="re2">:hidden</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; font-family<span class="re2">:Arial</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; font-size<span class="re2">:<span class="re3">12px</span></span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; font-weight<span class="re2">:bold</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; text-align<span class="re2">:center</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; float<span class="re2">:left</span>;<br />
<span class="br0">&#125;</span><br />
<span class="re1">.Content</span><br />
<span class="br0">&#123;</span><br />
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;height<span class="re2">:<span class="re3">198px</span></span>;<br />
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;border-top<span class="re2">:<span class="re3">1px</span></span> <span class="kw2">solid</span> <span class="re0">#<span class="nu0">333</span></span>;<br />
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;border-bottom<span class="re2">:<span class="re3">1px</span></span> <span class="kw2">solid</span> <span class="re0">#<span class="nu0">333</span></span>;<br />
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">background-color</span>:<span class="re0">#ececec</span>;<br />
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;display<span class="re2">:none</span>;<br />
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;width<span class="re2">:<span class="re3">0px</span></span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;float<span class="re2">:left</span>;<br />
<span class="br0">&#125;</span></div>
<p>An important thing to note here is the floats, In order to get the divs to position next to each other, they need to be floated or set to display:inline, I chose to use float.</p>
<p>Finally the Javascript:</p>
<p>I am not going to compare JavaScripts, I will just provide the modified function, and explain what changes were made.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> ContentWidth = <span class="nu0">200</span>;<br />
<span class="kw2">var</span> TimeToSlide = <span class="nu0">250.0</span>;</p>
<p><span class="kw2">var</span> openAccordion = <span class="st0">&#8221;</span>;</p>
<p><span class="kw2">function</span> runAccordion<span class="br0">&#40;</span>index<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">var</span> nID = <span class="st0">&quot;Content&quot;</span> + index;<br />
&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>openAccordion == nID<span class="br0">&#41;</span><br />
&nbsp; &nbsp; nID = <span class="st0">&#8221;</span>;</p>
<p>&nbsp; setTimeout<span class="br0">&#40;</span><span class="st0">&quot;animate(&quot;</span> + <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span> + <span class="st0">&quot;,&quot;</span> + TimeToSlide + <span class="st0">&quot;,&#8217;&quot;</span> + openAccordion + <span class="st0">&quot;&#8217;,'&quot;</span> + nID + <span class="st0">&quot;&#8217;)&quot;</span>, <span class="nu0">33</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; openAccordion = nID;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">function</span> animate<span class="br0">&#40;</span>lastTick, timeLeft, closingId, openingId<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">var</span> curTick = <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw2">var</span> elapsedTicks = curTick - lastTick;</p>
<p>&nbsp; <span class="kw2">var</span> opening = <span class="br0">&#40;</span>openingId == <span class="st0">&#8221;</span><span class="br0">&#41;</span> ? <span class="kw2">null</span> : document.<span class="me1">getElementById</span><span class="br0">&#40;</span>openingId<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw2">var</span> closing = <span class="br0">&#40;</span>closingId == <span class="st0">&#8221;</span><span class="br0">&#41;</span> ? <span class="kw2">null</span> : document.<span class="me1">getElementById</span><span class="br0">&#40;</span>closingId<span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>timeLeft &lt;= elapsedTicks<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>opening != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; opening.<span class="me1">style</span>.<span class="me1">width</span> = ContentWidth + <span class="st0">&#8216;px&#8217;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>closing != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; closing.<span class="me1">style</span>.<span class="me1">display</span> = <span class="st0">&#8216;none&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; closing.<span class="me1">style</span>.<span class="me1">width</span> = <span class="st0">&#8216;0px&#8217;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; timeLeft -= elapsedTicks;<br />
&nbsp; <span class="kw2">var</span> newClosedWidth = Math.<span class="me1">round</span><span class="br0">&#40;</span><span class="br0">&#40;</span>timeLeft/TimeToSlide<span class="br0">&#41;</span> * ContentWidth<span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>opening != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>opening.<span class="me1">style</span>.<span class="me1">display</span> != <span class="st0">&#8216;block&#8217;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; opening.<span class="me1">style</span>.<span class="me1">display</span> = <span class="st0">&#8216;block&#8217;</span>;<br />
&nbsp; &nbsp; opening.<span class="me1">style</span>.<span class="me1">width</span> = <span class="br0">&#40;</span>ContentWidth - newClosedWidth<span class="br0">&#41;</span> + <span class="st0">&#8216;px&#8217;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>closing != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; closing.<span class="me1">style</span>.<span class="me1">width</span> = newClosedWidth + <span class="st0">&#8216;px&#8217;</span>;</p>
<p>&nbsp; setTimeout<span class="br0">&#40;</span><span class="st0">&quot;animate(&quot;</span> + curTick + <span class="st0">&quot;,&quot;</span> + timeLeft +<span class="st0">&quot;,&#8217;&quot;</span> + closingId + <span class="st0">&quot;&#8217;,'&quot;</span> + openingId + <span class="st0">&quot;&#8217;)&quot;</span>, <span class="nu0">33</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>Now get ready for this, these are some monstrous changes!!  I mean seriously&#8230; not for the faint of heart.  The first thing I did of course was read through the code&#8230; then I read it again&#8230; and 3rd time just for good measure.  Then I opened up Find/Replace, and replaced the word <strong>height</strong> with the word <strong>width</strong> everywhere in the code.  I of course maintained capitalization where it was.  </p>
<p>Then I changed one other line of code:</p>
<p><strong>var nID = &#8220;Content&#8221; + index;</strong></p>
<p>This was originally:</p>
<p><strong>var nID = &#8220;Accordion&#8221; + index + &#8220;Content&#8221;;</strong></p>
<p>Since I changed the Content divs id tags to just Content#, I needed to change this line of code accordingly.  Like I said, I read through the code over and over.  Just to make sure everything was correct.  I could sit here and explain everything that the function does, but who really wants to read all of that when you can spend time playing with the accordion!</p>
<p>Two other important things to note:  At the top of the JavaScript, the two variables control the width that the content divs will expand to, and the amount of time in milliseconds that the animation will take.<br />
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.clickpopmedia.com/2008/05/05/twitter-feeds-made-simple/" title="Twitter feeds made simple.">Twitter feeds made simple. (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/03/12/ajax-and-php-getting-data-on-the-fly/" title="AJAX and PHP, getting data on the fly.">AJAX and PHP, getting data on the fly. (1)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/03/04/intro-to-website-dynamics/" title="Geek Time - Binary Clock">Geek Time - Binary Clock (0)</a></li>
<li><a href="http://www.clickpopmedia.com/2008/02/19/weekly-snip-o-codes/" title="Weekly Snip-O-Codes!">Weekly Snip-O-Codes! (0)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clickpopmedia.com/2008/06/05/a-cssjavascript-horizontal-accordion/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.clickpopmedia.com/2008/06/05/a-cssjavascript-horizontal-accordion/</feedburner:origLink></item>
	</channel>
</rss>
