Categories: How To | Flash Lite | Code Examples | Games
This page was last modified 19:24, 16 May 2008.
How to develop Flash Lite games for Nokia series 40 and S60 devices
From Forum Nokia Wiki
Contents |
Nokia series 40 and S60 devices with Flash Lite Game example
So you have decided that you would like to make a Flash Lite game for Nokia devices.
Before you start coding the game you should be aware of a few things about Mobile Devices and Flash Lite.
Device issues
Developing for a device means, we have a few limitations that we must keep in mind, when develop Flash Lite games or content.
- The screen resolution on a device tends to be much lower then that of a desktop computer. The mobile screen size is 128X160, 176X208, 240X320, 320X240 pixels in resolution. Compare to the desktop resolution of 800X600.
- The CPU tends to be slower on a device.
- The input options are different on a mobile devices and a desktop.
- The amount of RAM available to a mobile device compared to a desktop computer can differ very much. Making games that 2MB of Bitmap, Vector and sound run on desktop computer but not feasible on a mobile devices.
- Two key press at a same time not work. For example player run and jump same time. No mouse click and drag navigation.
Flash Lite issues
- Use vector graphics rather than bitmap graphics. Flash is vector based, so Flash file have small size it also automatically resize for large screen.
- Its also good idea to use bitmap images same time. Rather than vector graphics but when the game is run Flash Lite player has to calculate the vector on screen and we don't want anything to go slow down, because device RAM is limited. Bitmaps are pre-rendered and usually they look better too. But bitmap graphics pixilated when resize from their original size. Note: Develop single game support maximum devices.
- Use vector graphics, but not use lots of curves, add less anchor points and not use gradients .
- Use device fonts and use pixel fonts For example hooge 05_53
- Fonts are distorted when flash Lite file automatically scaled and small make them fonts blur or not readable.
- Use optimize curves to more optimize graphics. optimize graphic that look better. Not optimize too much.
- Use variable and predefine values, not use too much hard-code.
- To optimize the graphics use:
fscommand2("SetQuality",quality)
- Reuse your functions
- one of the most important thing in game development is:
- How well Flash Lite game actually play on mobile devices.
- How Responsive it is
- How smooth it is
Finally test on real Nokia device. Not final game tested on emulator only because there are few of action scripts are support on real devices.
Flash Lite 1.1 Game with simulated Array
When you are developing Flash Lite 1.1 game. you may think to use the array. But in flash Lite 1.1, you don't use the array. what to do?
- The solution is to develop simulate array by creating a set of variables or instance name.
- The eval function was used to simulate array.
- You can also use eval function to dynamically set and retrieve the value of a variable or instance name.
For example: A player eat bugs and add point with use of simulate array and predefine values.
- First you have an idea of game.
- you want to create a nice background for game.
- Define a 12X12 grid.
- player size 12X12 for four sides. For Up, Down, Left, Right positions .
- Make a instance name player set frame label up, Left, Right, Down. Stop them four frames.
- Create a bug and give a instance name b1, b2, b3, b4
- Make sure that both player and bug have registration point in left top corner.
- Now lets declare variables in frame.
- Maximum bug=total bugs.
/:max_bug=tot_bug=4
- Text variable for score.
/:score=0
Define event handler
- First move the player around screen.
Move a player in four direction. Move X and Y position 12 pixel.
tellTarget ("/player") { gotoAndStop(2); if (_root.player._x>22) { //_x and _y position and speed posX = _x-12; posY = _y; _x = posX; tellTarget ("/player") { gotoAndStop(2); }
- Predefine values of bug x and y position on screen.
- Check bugs on screen.
Use For loop to check the bugs on screen. crate simulated array to check the bugs and collision with player x and y position. If collision happened add score and decreased one bug on screen make bug visible false on screen. if player x, y coordinate and bug X, Y coordinate collide.
- Check if bug maximum equal to 0 then go to completed frame.
if (_root.max_bug<=0) { tellTarget ("_level0") { gotoAndPlay("completed"); } }
Code
//Left Key on (keyPress "<Left>") { tellTarget ("/player") { gotoAndStop(2); if (_root.player._x>22) { //_x and _y position and speed posX = _x-12; posY = _y; _x = posX; tellTarget ("/player") { gotoAndStop(2); } //Checking for bug for (i=1; i<=/:tot_bug; i++) { //Simulated Array if (eval("/:bug" add i add "0") == posX) { if (eval("/:bug" add i add "1") == posY) { // Add score _root.score += 10; _root.max_bug -= 1; tellTarget ("/b" add i) { _visible = false; } //check if bug max equal to 0 then go to completed frame if (_root.max_bug<=0) { tellTarget ("_level0") { gotoAndPlay("completed"); } } break; // this will terminate/exit the loop } } } } } } //Right key on (keyPress "<Right>") { tellTarget ("/player") { gotoAndStop(3); if (_root.player._x<140) { //_x and _y position and speed posX = _x+12; posY = _y; _x = posX; tellTarget ("/player") { gotoAndStop(3); } //Checking for bug for (i=1; i<=/:tot_bug; i++) { //Simulated Array if (eval("/:bug" add i add "0") == posX) { if (eval("/:bug" add i add "1") == posY) { //Add score _root.score += 10; _root.max_bug -= 1; trace("b" add i); tellTarget ("/b" add i) { _visible = false; } //check if bug max equal to 0 then go to completed frame if (_root.max_bug<=0) { tellTarget ("_level0") { gotoAndStop("completed"); } } break;// this will terminate/exit the loop } } } } } } //// Up key on (keyPress "<Up>") { ///Path tellTarget ("/player") { gotoAndStop(1); if (_root.player._y>24) { //_x and _y position and speed posX = _x; posY = _y-12; _y = posY; tellTarget ("/player") { gotoAndStop(1); } //Checking for bug for (i=1; i<=/:tot_bug; i++) { //Simulated Array if (eval("/:bug" add i add "0") == posX) { if (eval("/:bug" add i add "1") == posY) { //Add score _root.score += 10; _root.max_bug -= 1; trace("b" add i); tellTarget ("/b" add i) { _visible = false; } //check if bug max equal to 0 then go to completed frame if (_root.max_bug<=0) { tellTarget ("_level0") { gotoAndPlay("completed"); } } break;// this will terminate/exit the loop } } } } } } ////Down Key on (keyPress "<Down>") { ///Path tellTarget ("/player") { gotoAndStop(4); if (_root.player._y<176) { //_x and _y position and speed posX = _x; posY = _y+12; _y = posY; tellTarget ("/player") { gotoAndStop(4); } //Checking for bug for (i=1; i<=/:tot_bug; i++) { //Simulated Array if (eval("/:bug" add i add "0") == posX) { if (eval("/:bug" add i add "1") == posY) { _root.score += 10; _root.max_bug -= 1; trace("b" add i); tellTarget ("/b" add i) { _visible = false; } //check if bug max equal to 0 then go to completed frame if (_root.max_bug<=0) { tellTarget ("_level0") { gotoAndPlay("completed"); } } break;// this will terminate/exit the loop } } } } } }
Download
you can download an example with source code here:
Flash Lite Game
--Narender Raul
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Cannot use XML.load on Nokia 6300 via network | uwetronnier | Flash Lite on Nokia Devices | 8 | 2008-05-12 13:49 |
| Stand-alone Python app not launched correctly from other native app | bercobeute | Python | 2 | 2005-03-04 14:30 |
| How to make a Flash screensaver? | MobileVisuals | Flash Lite on Nokia Devices | 4 | 2008-01-03 13:35 |
| native code to Flash Player interface | marchywka | Symbian User Interface | 1 | 2005-03-04 02:20 |
| Flash Lite and C++ Integration | sysctl | General Symbian C++ | 4 | 2007-03-23 00:29 |

