Last weekend, I wanted to launch a Tetris game on my Android phone. After having tried some of them on the internet, I’ve decided to develop my own Tetris game, interacting with Touch and Gesture Events. The new Multitouch API introduced few months ago in Flash Player 10.1 can help developers to handle this new generation of events very easily. Classic approach: don’t reinvent the weel. A quick search on google: “open source as3 tetris”, and TADAAA!, I discovered this open source project: http://code.google.com/p/bigroom/wiki/TetrisGameEngine
This Tetris engine written in AS3 provides a sample. It took me few minutes to understand the basic behaviors of the engine. I compiled it using flash CS5, and was able to play with my keyboard (using the arrow keys). But, on my Android phone, I don’t want to display and use the native keyboard… I want to play with my fingers! Does it mean that I need to code a new project from scratch or switch to another langage ? Of course not. After having identified the Controler AS3 class, I’ve just added these lines of code to handle Touch Events:
Multitouch.inputMode = MultitouchInputMode.GESTURE;
root.stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);
private function onSwipe(evt:TransformGestureEvent):void{
// MOVE TO THE RIGHT
if(evt.offsetX > 0) _tetris.shiftRight();
// MOVE TO THE LEFT
if(evt.offsetX < 0) _tetris.shiftLeft();
// MOVE TO THE BOTTOM OF THE SCREEN
if(evt.offsetY > 0) _tetris.drop();
// ROTATION
if(evt.offsetY < 0) _tetris.rotateLeft();
}
Flash Tetris game on Android phones from michael chaize on Vimeo.



June is a long time away…
Can’t wait
I did the same, a few weeks ago. I stumbled upon this code http://wonderfl.net/c/f2Xu/ and I wanted to see how it would behave on a mobile device. I added less than 10 lines of Accelerometer handling code, and less than five minutes later, i played with it on my mobile phone.
As easy as pie!
Xaxa maybe we should email this to Mr Jobs…
Really nice post!
Loved the simple and sweet presentation.
Love it. I love Android and flash.
How exactly do you take a .fla file and export it to AIR 2.0 then create a .apk file from that? Do you need the AIR 2.0 Beta?
You’ll get an answer in the coming weeks, and I’ll post how I made it. You’ll see how easy it is.
On what version of androids does AIR2 run on?
You’ll get the answer next week at the Google I/O event.
Thanks
I am trying to recreate your steps as a tutorial, but I don’t understand how you imported the .fla, modified the .as and exported the .apk with Flash CS5. Thanks!
Hi, did you have any problems getting the TransformGestureEvent to work on the emulator. Doesn’t seem to want to accept gesture events for me for some reason…
I don’t think it can work on the emulator. You can try Device Central CS5 to get a Multi-touch emulator for Flash.