So I was curious about, what Flash can do on an Android Device. I wrote a little Testprogramm that does nothing more, than move a big image over the screen and infront of that draw a semi-transparent rectangle with some text in it. But I didn’t use any Android Device. I used Sony’s state of the art XPeria S, with dual Core 1,5Ghz and a 1280×720 Resolution.
Fillrate always is a problem, when it comes to software rendering. And the Flash-Plugin you see in your desktop browser is a software rendering engine. So I wondered, will my mobile device be able to run this at a framrate high enough, so I can build a game on top of that moving-background-thing. The result is frankly sort of disappointing. As soon as the animation takes of, the framerate is reduced from 56-60 to 20-30. For me that points towards a problem of fillrate.
Due to the fact that most new phones and tablet come with resolutions equal or bigger than those you have on your desktop, the hardware must be very powerful to fill the screen with rendered images. I think it’s crucial to access the hardware in an efficient way, and use the integrated graphics chip where you can. Which you cannot do in a flash context. The only thing you have there is maybe stage3D which is sort of immature and so low level, that you cannot use the same (simple) approach you use, when coding plane actionscript3 to the stage.
Today I saw this video of the new version of Unity3D, especially their character animation system work with loads of characters on an iPad. This is something that (i guess) will never be possible even with stage3D in a flash context. Sadly even the new Unity3D version does not feature a GUI-System, that Unity constantly promise to provide in the near future.
The program is mostly straight forward, here is the code used:
package { import flash.display.Bitmap; import flash.display.BlendMode; import flash.display.MovieClip; import flash.display.Shape; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.system.Capabilities; import flash.text.TextField; public class alphatest extends Sprite { [Embed(source="/resources/gfx/KWNetzwelt_2561.png")] public var bgImgClass:Class; private var bgImgInstance:Bitmap; public function get backgroundImage():Bitmap { if(!bgImgInstance) bgImgInstance = new bgImgClass(); return bgImgInstance; } private var time:Time; private var fpsDisplay:TextField; public function alphatest() { super(); // support autoOrients stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; stage.frameRate = 60; time = new Time(); fpsDisplay = new TextField(); fpsDisplay.scaleX = 3; fpsDisplay.scaleY = 3; fpsDisplay.x = 150; fpsDisplay.y = 100; // // The Bitmap // backgroundImage.scaleX = 1; backgroundImage.scaleY = 1; stage.addChild(backgroundImage); // // The GUI // generateGUI(); stage.addChild(fpsDisplay); stage.addEventListener(Event.ENTER_FRAME,onEnterFrame); } private var animate:Boolean = false; private function onClick(e:MouseEvent):void { animate = !animate; } private function onEnterFrame(e:Event):void { time.update(); if(Time.deltaTime != 0) { fpsDisplay.text = Math.round( 1/Time.deltaTime ) + " fps"; } var speed:Number = 0.5; var x:Number = - (backgroundImage.width - stage.stageWidth) / 2; var y:Number = - (backgroundImage.height - stage.stageHeight) / 2; if(animate) { x += backgroundImage.width / 10 * Math.sin(Time.time * speed); y += backgroundImage.height / 10 * Math.cos(Time.time * speed); } backgroundImage.x = backgroundImage.x + (x - backgroundImage.x) * Time.deltaTime * 3; backgroundImage.y = backgroundImage.y + (y - backgroundImage.y) * Time.deltaTime * 3; } private function generateGUI():void { var x:Number = 100; var y:Number = 50; var width:Number = stage.stageWidth - 250; var height:Number = stage.stageHeight - 300; trace(stage.stageWidth, stage.stageHeight); trace(stage.width, stage.height); trace(Capabilities.screenResolutionX, Capabilities.screenResolutionY); var s1:MovieClip = getSpriteRect(0xffffff,1.0,width,height); stage.addChild(s1); s1.x = x; s1.y = y; s1.blendMode = BlendMode.OVERLAY; s1.alpha = 0.8; var s2:MovieClip = getSpriteRect(0xffffff,1.0,width,height); stage.addChild(s2); s2.x = x; s2.y = y; s2.alpha = 0.5; s2.addEventListener(MouseEvent.CLICK,onClick); } private function getSpriteRect(_color:uint,_alpha:Number,_width:Number, _height:Number):MovieClip { var s1:MovieClip = new MovieClip(); s1.graphics.beginFill(_color,_alpha); s1.graphics.drawRect(0,0,_width,_height); s1.graphics.endFill(); return s1; } } } |
