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
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
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
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.
Giorgio Natili is Adobe community expert, a W3C member and a Forum Nokia Champion. He is head of his own company GNStudio, which has been operating in the web development filed for the past 6 years. His field of expertise focus on Adobe Flash, Fireworks, Dreamweaver, Coldfusion Flash Media Server, Flex and their integration, as well as accessibility both in html and Flash. More recently his interests have broadened to include developing mobile applications and e-learning tools. He also works on various education initiatives to spread awareness on accessibility issues, especially to flash developers.
He strongly believes in the need to spread new web-technologies by ‘evangelizing’ in the Italian development communities. As a result he has been an active member of the Igenium community (Macromedia Users Group), taking part as an invited speaker, in the 2003, 2004 and 2005 webb.it events where he held numerous seminars on Flash and related technologies. In 2005 and 2006 he participated in SMAU in Milan, again holding seminaries and training sessions. He also spoke at the Adobe Max in Chicago and Barcelona in 2007.
In 2003 he received the award “Sito Protagonista” from Macromedia Italy for the website www.alessandracellini.com.
Among his many successful projects the on-line version of the TV game show “Quiz show” for Einstein Multimedia, subsequently published in the portal www.libero.it, along with the implementation of a Rich Internet Application for visualizing in real time Italian soccer championship games results, for the principal Italian media group, Gruppo Espresso.
In 2005 he founded the Flash community Actionscript.it that he is still leading and animating.
Throughout 2005 he has been Mobile and Technological innovation consultant for Saatchi & Saatchi Italia where he developed the J2me version on the mobile application D&G for Interpreting.it.
Throughout 2006 his Studio has established close partnerships with the mobile content provider Jamba, developing mobile applications for the Jamba development team, and MTV Italia, for whom he developed a chat environment driven by flash media server.
In the first half of 2007 he develops Intelligere SCS, a powerful web based synchronous collaboration system, entirely developed in Flex, and releases it under an open source license. The passion for community work continues with the founding of Flexdevelopers.org.
Flash Lite 1.1 capabilities
paco3 | 05/02/2008, 11:58
Hi, First of all I am a complete ignorant about FlashLite, but I am a FlashDesigner (more graphic than ActionScript programer) but very enthusiastic and with a lot of energy to learn.
I have this question: in order to get the bigest target market for mobiles, it is smart to design the FlasLite files for FlashLite 1.1?.. is this a smart way of thinking?,
What i want to do are forms, not games, photos or video, just nice, eyecatching forms, so in order to do this flashLite1.1 is enough? what can you suggest me?
thanks
Paco