<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="http://blogs.forum.nokia.com/styles/rss.css" type="text/css"?>
<rdf:RDF 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns="http://my.netscape.com/rdf/simple/0.9/"
>

 <channel>
  <title>Giorgio Natili&#039;s Forum Nokia Blog</title>
  <link>http://blogs.forum.nokia.com/blog/giorgio-natilis-forum-nokia-blog</link>
  <description>A Forum Nokia Blog</description>
 </channel>
    <item>
   <title>Flash Lite 1.1 collisions</title>
   <description>&lt;p&gt;Flash Lite 1.1 collisions&lt;br /&gt;A common task you may need when you start to develop a Flash Lite 1.1 arcade game is to check the collision between the sprites on the screen.&lt;br /&gt;If you surf the web you may find tons of way to detect the collision in Flash but in Flash Lite 1.1 you have refer to the old ActionScript 1.0 syntax.&lt;br /&gt;In this post we&amp;rsquo;ll try to explore the building blocks of detecting collision through a sample in which a character have to get some gift that are attached on the screen in a random way (fig. 1).&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://mobile.actionscript.it/forum_nokia_entries/random.PNG&quot; border=&quot;0&quot; alt=&quot;fig. 1&quot; title=&quot;fig. 1&quot; width=&quot;182&quot; height=&quot;212&quot; /&gt;&amp;nbsp;&lt;br /&gt;fig. 1&lt;br /&gt;&lt;br /&gt;In order to complete this task we need to create a movie clip that contains the function that launches the gift (remember that Flash Lite 1.1 doesn&amp;rsquo;t support the functions so you store the script you need in a key frame associated to a label), a movie clip that call this function, a movie clip that store the script that moves the gift and that check the collisions and a movie clip used as a character.&lt;br /&gt;The first three movie clips are outside the stage (fig. 2).&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://mobile.actionscript.it/forum_nokia_entries/movieclips.png&quot; border=&quot;0&quot; alt=&quot;fig. 2&quot; title=&quot;fig. 2&quot; width=&quot;403&quot; height=&quot;49&quot; /&gt;&amp;nbsp;&lt;br /&gt;fig. 2&lt;br /&gt;&lt;br /&gt;The aim of the &amp;ldquo;functions&amp;rdquo; and &amp;ldquo;loop&amp;rdquo; movie clips are self explanatory because the first one contains the code that duplicate the &amp;ldquo;gift&amp;rdquo; movie clip on the stage&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new,courier&quot;&gt;// Duplicate the movieclip&lt;br /&gt;duplicateMovieClip(&amp;quot;../gift&amp;quot;, &amp;quot;gift_mc&amp;quot; add count, count);&lt;br /&gt;// Control the duplicated movie clip&lt;br /&gt;tellTarget(&amp;quot;../gift_mc&amp;quot; add count){&amp;nbsp;&lt;br /&gt;&amp;nbsp;// Set the position of the movieclip&lt;br /&gt;&amp;nbsp;_x = random(/:_width);&lt;br /&gt;&amp;nbsp;_y = 0;&amp;nbsp;&lt;br /&gt;&amp;nbsp;// Start to move&lt;br /&gt;&amp;nbsp;gotoAndPlay(&amp;quot;moving&amp;quot;);&lt;br /&gt;&amp;nbsp;// Set the max value for the y&lt;br /&gt;&amp;nbsp;set(&amp;quot;ymax&amp;quot;, /:screenHeight);&amp;nbsp;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;and the second one the call to this script at the end of its timeline.&lt;br /&gt;Let&amp;rsquo;s take a look inside the gift movie clip. &lt;br /&gt;Organize your timeline in order to have a a key frame with the label &amp;ldquo;moving&amp;rdquo; and a key frame with the label &amp;ldquo;removing&amp;rdquo; (fig. 4).&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;http://mobile.actionscript.it/forum_nokia_entries/timeline.png&quot; border=&quot;0&quot; alt=&quot;fig. 4&quot; title=&quot;fig. 4&quot; width=&quot;425&quot; height=&quot;73&quot; /&gt;&amp;nbsp;&lt;br /&gt;fig. 4&lt;br /&gt;&lt;br /&gt;The &amp;ldquo;moving&amp;rdquo; key frame modifies the value of the _y property and launches a loop inside which you check if the movie clip has reached an _y that is outside the screen or if it is colliding with the character on the stage&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: courier new,courier&quot;&gt;// Check if the movie clip is get from the sprite&lt;br /&gt;if(_y + _height &amp;gt; eval(&amp;quot;../sprite_mc&amp;quot;)._y ){&lt;br /&gt;&amp;nbsp;if(_x &amp;gt; eval(&amp;quot;../sprite_mc&amp;quot;)._x &amp;amp;&amp;amp; _x &amp;lt; eval(&amp;quot;../sprite_mc&amp;quot;)._x + eval(&amp;quot;../sprite_mc&amp;quot;)._width){&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;tellTarget(&amp;quot;../sprite_mc&amp;quot;){&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;gotoAndPlay(&amp;quot;getIt&amp;quot;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;removeMovieClip(&amp;quot;&amp;quot;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;// Check if the gift is outside the screen&lt;br /&gt;if (_y + _height &amp;gt;= ymax) {&amp;nbsp;&lt;br /&gt;&amp;nbsp; isLooping = false;&amp;nbsp;&lt;br /&gt;}else{&amp;nbsp;&lt;br /&gt;&amp;nbsp;isLooping = true;&amp;nbsp;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;the &amp;ldquo;removing&amp;rdquo; key frame changes the graphic of the movie clip and at the end of its timeline removes the movie clip from the stage&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new,courier&quot;&gt;removeMovieClip(&amp;quot;&amp;quot;);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;I&amp;rsquo;m pretty sure that everybody knows how to move the main character on the stage so I&amp;rsquo;ll not explain this stuff in detail, by the way for reference and in order to be clear this is the &lt;a href=&quot;http://mobile.actionscript.it/forum_nokia_entries/collision.zip&quot; target=&quot;_blank&quot;&gt;file&lt;/a&gt; described in this post.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
   <link>http://blogs.forum.nokia.com/blog/giorgio-natilis-forum-nokia-blog/2008/02/02/flash-lite-1.1-collisions</link>
      <pubDate>Sat, 02 Feb 2008 17:56:16 +0200</pubDate>   
  </item>
  </rdf:RDF>

