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

<channel>
	<title>2souldesign &#187; Tutorials</title>
	<atom:link href="http://www.2souldesign.net/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.2souldesign.net</link>
	<description>flash games for mobile devices</description>
	<lastBuildDate>Sat, 10 Apr 2010 23:31:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tutorial: How to make a Flight Clone</title>
		<link>http://www.2souldesign.net/2010/04/flightclone/</link>
		<comments>http://www.2souldesign.net/2010/04/flightclone/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 23:29:18 +0000</pubDate>
		<dc:creator>santoki</dc:creator>
				<category><![CDATA[Flight]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[flight clone]]></category>

		<guid isPermaLink="false">http://www.2souldesign.net/?p=417</guid>
		<description><![CDATA[Here&#8217;s the next installment to the tutorial series on how to make a gsensor game.

Today we are going to learn how to make the following game:

Note: the demo game above is NOT using the gsensor(for convenience), but the mouse. This tutorial will be using the gsensor.
This tutorial is buildup from a previous Gsensor tutorial. You [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the next installment to the tutorial series on how to make a gsensor game.</p>
<p><span id="more-417"></span></p>
<p>Today we are going to learn how to make the following game:</p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/04/advancedGsensorTutorial1.swf"><img style="border: 2px single gray;" src="http://www.2souldesign.net/wp-content/uploads/2010/04/flight_game.jpg" alt="" /></a></p>
<p>Note: the demo game above is NOT using the gsensor(for convenience), but the mouse. This tutorial will be using the gsensor.</p>
<p>This tutorial is buildup from a previous Gsensor tutorial. You can find it <a href="http://www.2souldesign.net/2010/03/how-to-make-gsensor-games-tutorial/">here</a>.</p>
<h2>Preparations</h2>
<p>Go on ahead and download the advancedGsensorTutorial.zip from the previous tutorial and open the .fla.</p>
<p>Create a new layer and label it ship.</p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/04/step1.jpg"><img class="alignnone size-full wp-image-429" title="step1" src="http://www.2souldesign.net/wp-content/uploads/2010/04/step1.jpg" alt="" width="298" height="200" /></a></p>
<p>Next draw anything that looks like a ship&#8230; here&#8217;s what mine looks like.</p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/04/step2.jpg"><img class="alignnone size-full wp-image-430" title="step2" src="http://www.2souldesign.net/wp-content/uploads/2010/04/step2.jpg" alt="" width="298" height="200" /></a></p>
<p>Go on ahead and select it and make it into a Movie Clip by right clicking and pressing Convert to Symbol.</p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/04/step3.jpg"><img class="alignnone size-full wp-image-431" title="step3" src="http://www.2souldesign.net/wp-content/uploads/2010/04/step3.jpg" alt="" width="298" height="380" /></a></p>
<p>Make sure to label the name as <strong>hero</strong>, check Export for Actionscript, and give it an Identifier name of <strong>hero</strong>. Click OK.</p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/04/step4.jpg"><img class="alignnone size-full wp-image-432" title="step4" src="http://www.2souldesign.net/wp-content/uploads/2010/04/step4.jpg" alt="" width="297" height="376" /></a></p>
<p>Great! Now you can delete the hero currently on the Stage because it will be dynamically added on to the screen (Do not delete the hero in the library).</p>
<p>Let&#8217;s go on ahead and prepare for blasters!</p>
<p>Draw a simple bullet/blaster and like the hero, let&#8217;s make it into a Movie Clip by right clicking and pressing Convert to Symbol or the shortcut F8.</p>
<p>Make sure to label the name as <strong>bullet</strong>, check Export for Actionscript, and  give it an Identifier name of <strong>bullet</strong>. Click OK.<a href="http://www.2souldesign.net/wp-content/uploads/2010/04/step5.jpg"></a></p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/04/step5.jpg"><img class="alignnone size-full wp-image-433" title="step5" src="http://www.2souldesign.net/wp-content/uploads/2010/04/step5.jpg" alt="" width="297" height="376" /></a></p>
<p>Like the hero, you can delete the bullet currently on the Stage because it  will be dynamically added on to the screen (Do not delete the bullet in  the library).</p>
<h2>Coding</h2>
<p>Our goal for coding will be to replace the default image with the cool hero ship we made and allow it to shoot those bullets we made earlier.</p>
<p>Go ahead and press F9 to open up the actions panel. Assuming you have not touched the code, find line 31 and let&#8217;s add a container.</p>
<pre>createEmptyMovieClip("container", 0);
</pre>
<p>This code allows us to store everything into a container MovieClip and control everything in a much more structured manner.</p>
<p>Next find line 36 which says:</p>
<pre>var mc:Object = _root.attachMovie("ball", "hero", _root.getNextHighestDepth());</pre>
<p>and modify it to say the following:</p>
<pre style="font-size: .87em;">var mc:Object = _root.<span style="color: #ff0000;">container</span>.attachMovie("<span style="color: #ff0000;">hero</span>", "hero", _root.<span style="color: #ff0000;">container</span>.getNextHighestDepth());</pre>
<p>If you&#8217;ve made the changes and test the movie out (or even play it on the cowon). You should be able to play with the ship with the gsensor.</p>
<p>Coding the bullet will now require a little more coding, but don&#8217;t worry we&#8217;ll go one step at a time.</p>
<p>Start on a new line on the bottom of the same Action layer, for me it was line 112.</p>
<p>Let&#8217;s begin by making a function for shooting a bullet:</p>
<pre>function shoot_bullet(obj:Object) {
 bcnt++;
 <span style="font-size: .78em;">var mc:Object = _root.container.attachMovie("bullet", "bullet"+bcnt, _root.container.getNextHighestDepth());</span>
 //centers the mc to the middle of the object.
 mc._x = obj._x;
 mc._y = obj._y;
 mc.spd = 10;
 mc.onEnterFrame = function() {
 //movement applied to this mc
 this._y -= this.spd;
 //bounding restrictions.
 if (this._y&lt;=0) {
 this.removeMovieClip();
 }
 };
}</pre>
<p>The following code creates a bullet on the center of the designated object (in our program the hero) and will move to the top of the screen at a speed of 10 pixel per frame and will be removed from the game once it reaches the y coordinate of 0.</p>
<p>You will notice that I am using a variable called bcnt. What is that? Well it is a counter as for how many bullets have been fired off. So let&#8217;s define the variable bcnt where all the other variables are defined. In our example, it&#8217;s line 27 right under the declaring of the variable gCurRotation add:</p>
<pre>var bcnt:Number = 0;
</pre>
<p>Now we are settled. All we need to do is have an action or an event that calls our newly defined function. Add the following action to the bottom of the code:</p>
<pre>onMouseDown = function(){
 shoot_bullet(_root.container.hero);
}
</pre>
<p>The following code responds to every time the user presses the screen/Mouse is down, the shoot_bullet function will be called causing the hero to shoot a bullet.</p>
<p>Awesome! Well that completes the first installment of making a flight clone. Hope you enjoyed it.</p>
<p>You can download all the files <a href="http://www.2souldesign.net/download/tutorialflightclone.zip">here</a>.</p>
<p>If you come across any trouble say it feel free to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.2souldesign.net/2010/04/flightclone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tutorial: How to make Gsensor Games</title>
		<link>http://www.2souldesign.net/2010/03/how-to-make-gsensor-games-tutorial/</link>
		<comments>http://www.2souldesign.net/2010/03/how-to-make-gsensor-games-tutorial/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 07:44:05 +0000</pubDate>
		<dc:creator>santoki</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[gsensor]]></category>

		<guid isPermaLink="false">http://www.2souldesign.net/?p=385</guid>
		<description><![CDATA[One of the reason Cowon&#8217;s s9 was a huge hit was its use of an accelerometer. This tutorial will teach you how to utilize its latest advanced gsensor API.


If you would like to just skip the tutorial and just download the file, you can get it here.

Otherwise, let&#8217;s get started.




1. Drawing our hero
If we are [...]]]></description>
			<content:encoded><![CDATA[<p>One of the reason Cowon&#8217;s s9 was a huge hit was its use of an accelerometer. This tutorial will teach you how to utilize its latest advanced gsensor API.</p>
<p><span id="more-385"></span></p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/03/tutorial1.jpg"><img class="alignnone size-full wp-image-392" title="tutorial1" src="http://www.2souldesign.net/wp-content/uploads/2010/03/tutorial1.jpg" alt="" width="286" height="272" /></a></p>
<p>If you would like to just skip the tutorial and just download the file, you can get it <a href="http://www.2souldesign.net/download/advancedGsensorTutorial.zip">here</a>.</p>
<p><a title="Download" href="http://www.2souldesign.net/download/advancedGsensorTutorial.zip" target="_blank"><img class="alignnone size-full wp-image-226" title="download" src="http://www.2souldesign.net/wp-content/uploads/2009/10/download.jpg" alt="download" width="168" height="52" /></a></p>
<p>Otherwise, let&#8217;s get started.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4820105881203470";
/* Homepage 300x250, created 1/28/10 */
google_ad_slot = "9812573839";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script></p>
<p><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>1. Drawing our hero</h2>
<p>If we are to move anything with our nifty Cowon G-Sensor, we&#8217;ll need a hero object &#8211; a ball. Let&#8217;s go on ahead and grab the Oval Tool (0) and draw a circle. Once you&#8217;ve made a circle select it and make it into a movie clip (F8) and name it &#8220;ball&#8221; and make sure to check Export for ActionScript and give it an Identifier name of &#8220;ball&#8221; and press OK (see picture below).</p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/03/pic2.jpg"><img class="alignnone size-full wp-image-393" title="pic2" src="http://www.2souldesign.net/wp-content/uploads/2010/03/pic2.jpg" alt="" width="422" height="387" /></a></p>
<h2>2. Coding our hero</h2>
<p>believe it or not, we are 1/2 way there! Well, almost there. Now go on ahead and create a new layer, label it action and lock the layer (see image below).</p>
<p><a href="http://www.2souldesign.net/wp-content/uploads/2010/03/pic3.jpg"><img class="alignnone size-full wp-image-394" title="pic3" src="http://www.2souldesign.net/wp-content/uploads/2010/03/pic3.jpg" alt="" width="319" height="176" /></a></p>
<p>Now the best part&#8230; the code. Press F9 and enter the following code in the &#8220;Actions&#8221; layer:</p>
<pre>/* Variables */
// Always Initialized Variables
var setX:Number = 0;
var setY:Number = 0;
var setZ:Number = 0;

var preX:Number = 0;
var preY:Number = 0;
var preZ:Number = 0;
var DIR:Number = 0;

var curX:Number = 0;
var curY:Number = 0;
var curZ:Number = 0;
var gCurRotation:Number = -1;

//Callibrates the current position of the s9 as the "initial position"
SetXYZ();
stop();

//creates hero with .4 speed sensitivity;
create_hero(.4);
function create_hero(spd:Number) {
//creates a mc and links the mc labeled "ball" and names it hero.
var mc:Object = _root.attachMovie("ball", "hero", _root.getNextHighestDepth());
//centers the mc to the middle of the screen.
mc._x = Stage.width/2;
mc._y = Stage.height/2;
//sensor speed;
mc.sensor_spd = spd;
mc.onEnterFrame = function() {
//the code that allows movement based off of the xyz movement.
_root.ReadXYZ();

//movement applied to this mc
this._x = this._x+this.sensor_spd*_root.curX;
this._y = this._y+this.sensor_spd*_root.curY;

//bounding restrictions.
if (this._x&gt;=480) {
this._x = 480;
}
if (this._x&lt;=0) { this._x = 0; } if (this._y&gt;=272) {
this._y = 270;
}
if (this._y&lt;=0) { this._y = 0; } }; } // s9 Accellerometer function
function SetXYZ():Void { trace("set() working!");
setX = ext_fscommand2("GetEtcTASValueX");
setY = ext_fscommand2("GetEtcTASValueY");
setZ = ext_fscommand2("GetEtcTASValueZ");
if (setZ&gt;0) {
DIR = 1;
} else {
DIR = -1;
}
preX = setX;
preY = setY;
preZ = setZ;
}
function ReadXYZ() {
curX = ext_fscommand2("GetEtcTASValueX");
curY = ext_fscommand2("GetEtcTASValueY");
curZ = ext_fscommand2("GetEtcTASValueZ");

curX = Calibration(curX, preX);
curY = Calibration(curY, preY);
curZ = Calibration(curZ, preZ);

preX = curX;
preY = curY;
preZ = curZ;
if (setZ&gt;=0 &amp;&amp; curZ&gt;=0 || setZ&lt;0 &amp;&amp; curZ&lt;0) {
curY = curY-setY;
} else if (curY&lt;0) { curY = -512-curY-setY;
} else { curY = 512-curY-setY; }
curX = curX-setX;
curY = curY*DIR*_root.gCurRotation;
curX = curX*DIR*_root.gCurRotation;
}
function Calibration(cur:Number, pre:Number):Number {
if (Math.abs(cur, pre)&gt;80) {
return (pre);
} else if (cur == 0) {
return (pre);
} else {
return (cur);
}
}</pre>
<h2>3. In Action!</h2>
<p>If everything went correctly, the ball hero you created earlier should be spawned in the center, but unable to move. The hero is unable to move since it is moved based on the Gsensor movement of the Cowon. If an output prompt prints, &#8220;set() working!&#8221; Then it worked. Otherwise, you may have done something wrong.</p>
<p>The code has been commented where needed in describing everything where needed. If you feel the movement is too fast or too slow, you can change the initial speed by changing the variable on the hero:</p>
<p>&#8220;create_hero(.4);&#8221; // change the .4 to any number;</p>
<p>Again if you would like the source code you can download it <a href="../download/advancedGsensorTutorial.zip">here</a>.</p>
<p>Depending on the feedback, I&#8217;ll try making this into a series &#8211; a break from me making games.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.2souldesign.net/2010/03/how-to-make-gsensor-games-tutorial/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Advanced G-sensor tutorial in the works!</title>
		<link>http://www.2souldesign.net/2009/05/advanced-g-sensor-tutorial-in-the-works/</link>
		<comments>http://www.2souldesign.net/2009/05/advanced-g-sensor-tutorial-in-the-works/#comments</comments>
		<pubDate>Fri, 08 May 2009 21:34:26 +0000</pubDate>
		<dc:creator>santoki</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.2souldesign.net/?p=145</guid>
		<description><![CDATA[It&#8217;s been a while since the latest x.30b firmware has been released for the Cowon s9, but from that recent update a new game was featured known as &#8220;hunter.&#8221; From that game it was revealed that the S9 was not just limited to 4 directions, but also had a Z-axis for a precise tilt measurement.
The [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since the latest x.30b firmware has been released for the Cowon s9, but from that recent update a new game was featured known as &#8220;hunter.&#8221; From that game it was revealed that the S9 was not just limited to 4 directions, but also had a Z-axis for a precise tilt measurement.</p>
<p>The code to interepret the precise tilts have increased several folds from the original code with a few more complimenting functions, but after several heuristic attempts I think I&#8217;ve found the most simplest coding method for utilizing the g-sensor.</p>
<p>I will be releasing a tutorial based on these changes shortly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.2souldesign.net/2009/05/advanced-g-sensor-tutorial-in-the-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: Cowon s9 G-Sensor Tutorial</title>
		<link>http://www.2souldesign.net/2009/04/tutorial-cowon-s9-g-sensor-tutorial/</link>
		<comments>http://www.2souldesign.net/2009/04/tutorial-cowon-s9-g-sensor-tutorial/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 04:43:46 +0000</pubDate>
		<dc:creator>santoki</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.2souldesign.net/?p=128</guid>
		<description><![CDATA[
After several weeks of preparation, I&#8217;m glad to release the Cowon s9 G-sensor tutorial.
I will assume throughout the tutorial that you know the basics of flash. If not, there are plenty of flash tutorial sites available with a simple search. I will be using Flash Professional CS4 so there will be some minor graphical difference, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-129" title="G-sensor Tutorial" src="http://www.2souldesign.net/wp-content/uploads/2009/04/main_image.jpg" alt="G-sensor Tutorial" width="316" height="401" /></p>
<p>After several weeks of preparation, I&#8217;m glad to release the Cowon s9 G-sensor tutorial.</p>
<p>I will assume throughout the tutorial that you know the basics of flash. If not, there are plenty of flash tutorial sites available with a simple search. I will be using Flash Professional CS4 so there will be some minor graphical difference, but the concept will be the same as well as the code.</p>
<p>If you only need to see the example source file, then you can download it <a title="g_sensor" href="http://www.2souldesign.net/download/g-sensor_v1.zip">here</a>.</p>
<p>Otherwise, you can follow along through this tutorial and begin creating a game that utilizes the G-Sensor -let&#8217;s get started!</p>
<h2>Prerequisites</h2>
<p>You will need a Flash IDE program that is able to author Actionscript 2.0 Any Flash IDE from Flash MX and above will work. You can purchase or try the latest version of Flash CS4 <a title="Adobe Flash Link" href="http://www.adobe.com/products/flash/" target="_blank">here</a>.</p>
<h2>The Setup</h2>
<p><strong>1. Create a new flash document with AS 2.0 and change the size to 480 x 272. </strong></p>
<p style="padding-left: 30px;"><em>Note: It is crucial that you open the flash document in AS2.0 because the Cowon s9 will not be able to read AS3.0 flash files and AS1.0 will not be able to save data.</em></p>
<p><strong>2. We will also need to set the FPS (Frames per second) to 24.</strong></p>
<p><strong><img class="alignnone size-full wp-image-120" title="pic1" src="http://www.2souldesign.net/wp-content/uploads/2009/03/pic1.jpg" alt="pic1" width="475" height="121" /></strong></p>
<p><strong>3. On “Layer 1″, relabel it to “actions” and lock the layer.</strong></p>
<p><strong>4. Create one additional layers and label it: objects.</strong></p>
<p style="padding-left: 30px;"><em>Note: While not crucial to lock the frame label and/or the actions layer it is a good programming habit.</em></p>
<p style="padding-left: 30px;"><em><img class="alignnone size-full wp-image-133" title="tut21" src="http://www.2souldesign.net/wp-content/uploads/2009/04/tut21.jpg" alt="tut21" width="241" height="144" /></em></p>
<p style="padding-left: 30px;">
<p style="padding-left: 30px;"><em><br />
</em></p>
<p><em> </em></p>
<h2>The Objects.</h2>
<p>The next portion will focus on the objects you will be interacting with.</p>
<p><strong>5. On the second frame of the Object Layer, add some text.<br />
</strong></p>
<p style="padding-left: 30px;">Click on the text tool and add &#8220;This side is up!&#8221;</p>
<p><strong>6. If your feeling artistic, draw for yourself an arrow using the shape tools.</strong></p>
<p><strong><img class="alignnone size-full wp-image-134" title="tut1" src="http://www.2souldesign.net/wp-content/uploads/2009/04/tut1.jpg" alt="tut1" width="480" height="270" /></strong></p>
<p><strong>7. Once your finished select both the text and the arrow and make it into a movie clip by pressing F8 and name it &#8220;mc&#8221; with the registration point in the center.</strong></p>
<p><strong><img class="alignnone size-full wp-image-135" title="tut3" src="http://www.2souldesign.net/wp-content/uploads/2009/04/tut3.jpg" alt="tut3" width="424" height="124" /></strong></p>
<p><strong>8. Now give this movie clip a new instance name of &#8220;mc.&#8221;</strong></p>
<p><strong><br />
</strong></p>
<h2>The Code.</h2>
<p>This is what allows flash to act upon the g-sensor.</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>8. Open up the Actions window by pressing F9 on the “actions” layer of the first frame and insert the following code:</strong></p>
<pre class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;"><code>var g_sensor:<span style="color: #3366ff;">Number</span> = ext_fscommand2(<span style="color: #339966;">"GetEtcTASValue"</span>);
mc.<span style="color: #3366ff;">onEnterFrame</span> = function () {
    g_sensor = ext_fscommand2(<span style="color: #339966;">"GetEtcTASValue"</span>);
   <span style="color: #3366ff;"> switch </span>(g_sensor) {
        case 0 :
            this._rotation = 0;
           <span style="color: #3366ff;"> break;</span>
        case 1 :
            this._rotation = 90;
          <span style="color: #3366ff;">  break;</span>
        case 2 :
            this._rotation = 180;
       <span style="color: #3366ff;">     break;</span>
        case 3 :
            this._rotation = 270;
        <span style="color: #3366ff;">    break;</span>
    }
};

</code></pre>
<p><strong>9. Code Explanation:</strong></p>
<p class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;"><code>var g_sensor:<span style="color: #3366ff;">Number</span> = ext_fscommand2(<span style="color: #339966;">"GetEtcTASValue"</span>);</code></p>
<p class="code" style="margin: 0pt; padding-top: 0pt; padding-right: 0pt; padding-bottom: 0pt;">The variable &#8220;g_sensor&#8221; is a variable (Can be labeled anything) with a data type of Number. The function call to ext_fscommand2(&#8220;GetEtcASValue&#8221;) checks for the direction of the s9&#8217;s current state and assigns it to g_sensor.</p>
<p class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;">
<p class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;">
<p class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;"><code>mc.<span style="color: #3366ff;">onEnterFrame</span> = function () {<br />
...<br />
}<br />
</code></p>
<p class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;">
<p class="code" style="margin: 0pt; padding-top: 0pt; padding-right: 0pt; padding-bottom: 0pt;">mc will now (based on the fps) continually run the following function.</p>
<p class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;">
<p class="code" style="margin: 0pt; padding: 0pt 0pt 0pt 30px;"><code>g_sensor = ext_fscommand2(<span style="color: #339966;">"GetEtcTASValue"</span>);</code></p>
<p>The value g_sensor will be updated now continually.</p>
<p style="padding-left: 30px;">switch (g_sensor) {<br />
case 0 :<br />
this._rotation = 0;<br />
break;<br />
case 1 :<br />
this._rotation = 90;<br />
break;<br />
case 2 :<br />
this._rotation = 180;<br />
break;<br />
case 3 :<br />
this._rotation = 270;<br />
break;<br />
}</p>
<p>The switch statement will test for the cases of 0,1,2,3. Each 45 degree change will increment from 0-4 and reset back to 0 after a full revolution.</p>
<p><strong>Test your movie! If you did everything correctly place the .swf file into your flash directory and watch that sign move according to your rotation.</strong></p>
<p><strong>We are done setting up the g-sensor! If you are lost, or would like to start with the file I have created  you can download it <a href="http://www.2souldesign.net/download/g-sensor_v1.zip">here</a>.</strong></p>
<h1>Alterations:</h1>
<p>I&#8217;ve made a game (a simulation) of a ball that you can play around with that utilizes the g-sensor. This simulation allows you to play around with the gravity, the friction, and the bounce back power.</p>
<p>You can download it <a href="http://www.2souldesign.net/download/g-sensor_ball_v1.zip">here</a>.</p>
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://www.2souldesign.net/2009/04/tutorial-cowon-s9-g-sensor-tutorial/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Tutorial: Saving data in flash.</title>
		<link>http://www.2souldesign.net/2009/03/saving-data/</link>
		<comments>http://www.2souldesign.net/2009/03/saving-data/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 06:40:30 +0000</pubDate>
		<dc:creator>santoki</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://www.2souldesign.net/?p=77</guid>
		<description><![CDATA[
In this tutorial you will learn how to save data in flash through a small touch tag game for the Cowon s9. I will assume throughout the tutorial that you know the basics of flash. If not, there are plenty of flash tutorial sites available with a simple search. I will be using Flash Professional [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-104" title="tutorial" src="http://www.2souldesign.net/wp-content/uploads/2009/03/tutorial.jpg" alt="tutorial" width="500" height="263" /></p>
<p>In this tutorial you will learn how to save data in flash through a small touch tag game for the Cowon s9. I will assume throughout the tutorial that you know the basics of flash. If not, there are plenty of flash tutorial sites available with a simple search. I will be using Flash Professional CS3 so there will be some minor graphical difference, but the concept will be the same as well as the code.</p>
<p>If you only need to see the example source file, then you can download it <a title="download" href="http://www.2souldesign.net/download/01_tut_3.zip" target="_blank">here</a>.</p>
<p>Otherwise, you can follow along through this tutorial and begin creating a game that utilizes Shared Objects &#8211; the means to save data with your Cowon s9.</p>
<h2>Prerequisites</h2>
<p>You will need a Flash IDE program that is able to author Actionscript 2.0 Any Flash IDE from Flash MX and above will work. You can purchase or try the latest version of flash CS4 <a title="Adobe Flash Link" href="http://www.adobe.com/products/flash/" target="_blank">here</a>.</p>
<h2>The Setup</h2>
<p><strong>1. Create a new flash document with AS 2.0 and change the size to 480 x 272. </strong></p>
<p style="padding-left: 30px;"><em>Note: It is crucial that you open the flash document in AS2.0 because the Cowon s9 will not be able to read AS3.0 flash files and AS1.0 will not be able to save data.</em></p>
<p><strong>2. We will also need to set the FPS (Frames per second) to 24.</strong></p>
<p><strong><img class="alignnone size-full wp-image-89" title="The Properties" src="http://www.2souldesign.net/wp-content/uploads/2009/03/pic1.jpg" alt="The Properties" width="475" height="121" /></strong></p>
<p><strong></strong></p>
<p><strong>3. On &#8220;Layer 1&#8243;, relabel it to &#8220;actions&#8221; and lock the layer.</strong></p>
<p><strong>4. Create three additional layers and label them accordingly: frame label (locked), text, object.</strong></p>
<p style="padding-left: 30px;"><em>Note: While not crucial to lock the frame label and/or the actions layer it is a good programming habit.</em></p>
<p style="padding-left: 30px;"><em><img class="alignnone size-full wp-image-93" title="4 layers" src="http://www.2souldesign.net/wp-content/uploads/2009/03/pic2.jpg" alt="4 layers" width="175" height="121" /><br />
</em></p>
<p><em></em></p>
<p><strong>5. We will need 4 frames total to cover for the following games states: initialization, main menu, play game state, end state.</strong></p>
<p><strong>6. Name the last frame of the frame label layer with &#8220;gameover&#8221; and the third frame with &#8220;game&#8221;</strong></p>
<p><strong>We are done setting up the scene. If you are lost, or would like to start with the file I have created so far you can download it <a title="download" href="http://www.2souldesign.net/download/01_tut_1.zip">here</a>.</strong></p>
<p><strong><br />
</strong></p>
<h2>The Objects.</h2>
<p>The next portion will focus on the objects you will be interacting with.</p>
<p><strong>7. On the second frame of the Object Layer, add a button. You can do this manually, or you can add a common library button. </strong></p>
<p style="padding-left: 30px;">Windows &gt;&gt; Common Libraries &gt;&gt; Buttons</p>
<p><strong>8. Add a dynamic text field on the Text Layer with a variable name of &#8220;highscore&#8221;</strong></p>
<p><strong>9. Add any text or decoration you feel fitting for a title/menu screen.</strong></p>
<p><strong><img class="alignnone size-full wp-image-123" title="pic3" src="http://www.2souldesign.net/wp-content/uploads/2009/03/pic3.jpg" alt="pic3" width="500" height="353" /><br />
</strong></p>
<p><strong>9. On the the third frame in the Object Layer, Create a circle with Oval Tool with size of 100 x 100 and place it somewhere on the canvas. </strong></p>
<p><strong>10. Convert the circle you have just made to a Movie Clip instance by </strong></p>
<p style="padding-left: 30px;">Double Click on it to select it<br />
Press F8 and choose &#8220;Movie Clip&#8221; under Behavior radio button<br />
Click OK</p>
<p><strong>11. Give the new Movie Clip the instance name of &#8220;ball&#8221;</strong></p>
<p><strong><img class="alignnone size-full wp-image-124" title="pic4" src="http://www.2souldesign.net/wp-content/uploads/2009/03/pic4.jpg" alt="pic4" width="229" height="353" /><br />
</strong></p>
<p><strong>12. Create three new dynamic text on the Text Layer with the variable names of &#8220;timer&#8221;, &#8220;score&#8221;, &#8220;highscore&#8221;. Place them where you want them listed. Remember to add static texts to label what each dynamic text represents.<br />
</strong></p>
<p><strong><img class="alignnone size-full wp-image-125" title="pic5" src="http://www.2souldesign.net/wp-content/uploads/2009/03/pic5.jpg" alt="pic5" width="500" height="383" /><br />
</strong></p>
<p><strong>13. Lastly, on the last frame ( the game over screen) of the Object Layer, add another button.</strong></p>
<p><strong>14. Add one last dynamic text labeled &#8220;score&#8221;.</strong></p>
<p><strong>15. Finish the Game Over screen by decorating it to your will.</strong></p>
<p><strong><img class="alignnone size-full wp-image-126" title="pic6" src="http://www.2souldesign.net/wp-content/uploads/2009/03/pic6.jpg" alt="pic6" width="500" height="390" /><br />
</strong></p>
<p><strong>We are done setting up the visual scene. If you are lost, or would like to start with the file I have created so far you can download it <a title="download" href="http://www.2souldesign.net/download/01_tut_2.zip" target="_blank">here</a>.</strong></p>
<h2>The Code.</h2>
<p>This is what allows flash to save data.</p>
<p style="padding-left: 30px;">
<p><strong></strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p><strong>16. Open up the Actions window by pressing F9 on the &#8220;actions&#8221; layer of the first frame and insert the following code: </strong></p>
<ol>score_record = SharedObject.getLocal(&#8220;name_of_file&#8221;);</p>
<p>if (score_record.data.highscore == undefined){</ol>
<blockquote style="padding-left: 30px;"><p>highscore = 0;</p></blockquote>
<ol>} else {</ol>
<blockquote style="padding-left: 30px;"><p>highscore = score_record.data.highscore;</p></blockquote>
<ol>}</ol>
<p><strong>5. Let&#8217;s see what this does:</strong></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">score_record = SharedObject.getLocal(&#8220;name_of_file&#8221;);</span></p>
<p style="padding-left: 30px;">// Replace &#8220;name_of_file&#8221; to the filename you choose for the Shared Object.</p>
<p style="padding-left: 30px;">// The variable &#8220;score_record&#8221; is the name for the data stored.</p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">highscore = 0;</span></p>
<p style="padding-left: 30px;">// if no highscore has been defined, it will be initialized to 0.</p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">highscore = score_record.data.highscore;</span></p>
<p style="padding-left: 30px;">// if a highscore has been defined, it will be set to the saved highscore.</p>
<p><strong>16. On the second frame insert the following code: </strong></p>
<p style="padding-left: 30px;">stop();<br />
var score:Number = 0;<br />
var initial_timer:Number = 120;<br />
var timer:Number = initial_timer;</p>
<p><strong>17. Let&#8217;s see what this does:</strong></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">var score:Number = 0;</span><br />
// The score is initially set to 0.</p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">var initial_timer:Number = 120;</span><br />
// We set the initial timer to 10 seconds.<br />
// In this example we have 120 because we have 24 fps. eg: 24 fps * 5 sec = 120.</p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">var timer:Number = initial_timer;</span><br />
// We then set the timer to the initial timer.</p>
<p><strong>18. On the third frame insert the following code: </strong></p>
<p style="padding-left: 30px;">stop();<br />
onEnterFrame = function(){</p>
<p style="padding-left: 60px;">_root.timer-=1;<br />
if (score &gt; highscore){</p>
<p style="padding-left: 90px;">highscore = score;</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 60px;">if(timer &lt; 0 ){</p>
<p style="padding-left: 90px;">gotoAndStop(&#8220;gameover&#8221;);</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">}</p>
<p>ball.onLoad = function(){</p>
<p style="padding-left: 60px;">this._x = random(480-this._width)+this._width/2;<br />
this._y = random(272-this._height)+this._height/2;</p>
<p style="padding-left: 30px;">}</p>
<p>ball.onPress = function(){</p>
<p style="padding-left: 60px;">_root.score+=1;<br />
_root.timer += 5;<br />
this._x = random(480-this._width)+this._width/2;<br />
this._y = random(272-this._height)+this._height/2;</p>
<p style="padding-left: 30px;">}</p>
<p><strong>19. </strong><strong>Add the following code to the button on the Object Layer </strong><strong>:</strong></p>
<p style="padding-left: 30px;">on(release){<br />
_root.gotoAndPlay(&#8220;game&#8221;);</p>
<p style="padding-left: 30px;">}<strong><br />
</strong></p>
<p><strong>20. Let&#8217;s see what this does:</strong></p>
<p style="padding-left: 30px;">// onEnterFrame is our main loop<br />
<span style="color: #3366ff;">onEnterFrame = function(){</span></p>
<p style="padding-left: 60px;">// The variable timer looses one every loop.<br />
<span style="color: #3366ff;">_root.timer-=1;</span></p>
<p style="padding-left: 60px;">// If the player reaches a score that is greater than the current highscore,<br />
// the highscore will be replaced with the current score.<br />
<span style="color: #3366ff;">if (score &gt; highscore){</span></p>
<p style="padding-left: 90px;"><span style="color: #3366ff;">highscore = score;<br />
</span></p>
<p style="padding-left: 60px;"><span style="color: #3366ff;">}</span></p>
<p style="padding-left: 60px;">// If the timer is less than 0 the game will end to the &#8220;gameover&#8221; framelabel.<br />
<span style="color: #3366ff;">if(timer &lt; 0 ){</span></p>
<p style="padding-left: 90px;"><span style="color: #3366ff;">gotoAndStop(&#8220;gameover&#8221;);<br />
</span></p>
<p style="padding-left: 60px;"><span style="color: #3366ff;">}</span></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">}</span></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">ball.onLoad = function(){</span></p>
<p style="padding-left: 60px;">/*<br />
To randomize the ball&#8217;s next location we have this code:<br />
We first randomize the value of the screen size minus the ball&#8217;s height.<br />
We then add it&#8217;s radius to create a offset from the center.<br />
The same principal is done for the height.<br />
*/</p>
<p style="padding-left: 60px;"><span style="color: #3366ff;">this._x = random(480-this._width)+this._width/2;<br />
this._y = random(272-this._height)+this._height/2;</span></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">}</span></p>
<p style="padding-left: 30px;">// This function activates whenever the ball movieclip is pressed.<br />
<span style="color: #3366ff;">ball.onPress = function(){</span></p>
<p style="padding-left: 60px;">// score is incremented by one for every successful click.<br />
<span style="color: #3366ff;">_root.score+=1;</span></p>
<p style="padding-left: 60px;">// A bonus time of 5 is given for a successful press.<br />
<span style="color: #3366ff;">_root.timer += 5;</span><br />
/*<br />
To randomize the ball&#8217;s next location we have this code:<br />
We first randomize the value of the screen size minus the ball&#8217;s height.<br />
We then add it&#8217;s radius to create a offset from the center.<br />
The same principal is done for the height.<br />
*/<br />
<span style="color: #3366ff;">this._x = random(480-this._width)+this._width/2;<br />
this._y = random(272-this._height)+this._height/2;</span></p>
<p style="padding-left: 30px;">}<strong></strong></p>
<p><strong>21. On the fourth frame insert the following code: </strong></p>
<p style="padding-left: 30px;">stop();<br />
if (score&gt;=highscore) {</p>
<p style="padding-left: 60px;">score_record.data.highscore = score;<br />
score_record.flush();</p>
<p style="padding-left: 30px;">}</p>
<p><strong>22. Let&#8217;s see what this does:</strong></p>
<p style="padding-left: 30px;">// A record is set!<br />
<span style="color: #3366ff;">if (score&gt;=highscore) {</span></p>
<p style="padding-left: 60px;">// We now set the score to the highscore variable.<br />
<span style="color: #3366ff;"> score_record.data.highscore = score;</span><br />
// The score is saved to the Shared Object.<br />
<span style="color: #3366ff;"> score_record.flush();</span></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">}</span></p>
<p><strong>23. Finally add the following code to the button on the Object Layer. </strong></p>
<p style="padding-left: 30px;">on(release){<br />
_root.score = 0;<br />
_root.timer = _root.initial_timer;<br />
_root.gotoAndPlay(&#8220;game&#8221;);<br />
}</p>
<p><strong>24. Believe it or not, you are finished. If you did everything right, after testing your movie (ctrl+Enter) you should be able to save your new game. </strong><strong>If you are lost, or would like to start with the file I have created so far you can download it <a title="download" href="http://www.2souldesign.net/download/01_tut_3.zip" target="_blank">here</a>.</strong></p>
<p><strong>If you have any questions, thoughts, suggestions and/or comments, feel free to post them here. If there is an error in my post feel free to point them out as well.</strong></p>
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://www.2souldesign.net/2009/03/saving-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
