You Are Here:

Community: Blogs

Giorgio Natili's Forum Nokia Blog

Flash Lite 1.1 collisions

gioorgionatili | 02 February, 2008 17:56

Flash Lite 1.1 collisions
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.
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.
In this post we’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).

fig. 1 
fig. 1

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’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.
The first three movie clips are outside the stage (fig. 2).

fig. 2 
fig. 2

The aim of the “functions” and “loop” movie clips are self explanatory because the first one contains the code that duplicate the “gift” movie clip on the stage

// Duplicate the movieclip
duplicateMovieClip("../gift", "gift_mc" add count, count);
// Control the duplicated movie clip
tellTarget("../gift_mc" add count){ 
 // Set the position of the movieclip
 _x = random(/:_width);
 _y = 0; 
 // Start to move
 gotoAndPlay("moving");
 // Set the max value for the y
 set("ymax", /:screenHeight); 
}

and the second one the call to this script at the end of its timeline.
Let’s take a look inside the gift movie clip.
Organize your timeline in order to have a a key frame with the label “moving” and a key frame with the label “removing” (fig. 4).

fig. 4 
fig. 4

The “moving” 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

// Check if the movie clip is get from the sprite
if(_y + _height > eval("../sprite_mc")._y ){
 if(_x > eval("../sprite_mc")._x && _x < eval("../sprite_mc")._x + eval("../sprite_mc")._width){ 
  tellTarget("../sprite_mc"){  
   gotoAndPlay("getIt");   
  }  
  removeMovieClip("");    
 }
}
// Check if the gift is outside the screen
if (_y + _height >= ymax) { 
  isLooping = false; 
}else{ 
 isLooping = true; 
}

the “removing” key frame changes the graphic of the movie clip and at the end of its timeline removes the movie clip from the stage

removeMovieClip("");

I’m pretty sure that everybody knows how to move the main character on the stage so I’ll not explain this stuff in detail, by the way for reference and in order to be clear this is the file described in this post.

 

 
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia