Blitting is slow in the iPad 2
Hello, I've been trying to implement the blitting technique (as explained here: http://gotoandlearn.com/play.php?id=145 )
to add some slide screen transitions in my app. To do that, I capture the screens with the draw() method of BitmapData
an perform a Tween animation between both using a Bitmap canvas.
This is my code:
private var canvas:BitmapData, canvasBitmap:Bitmap, currentScreen:Sprite, zeroPoint:Point = Point(0,0);
public var fromScreen:BitmapData, toScreen:BitmapData, currentX:int, slideAni:Tween, goingBack:Boolean;
public function transition_start(noCapture:Boolean = false):void{
screenCapture(toScreen, currentScreen);
addChild(canvasBitmap);
slideAni = new Tween(this, 'currentX', fl.transitions.easing.Regular.easeOut,
(goingBack ? stage.width : 0),
(goingBack ? 0 : stage.width),
Settings.screenAnimationTime / 1000,
true
);
slideAni.addEventListener(TweenEvent.MOTION_CHANGE, transition_render);
slideAni.addEventListener(TweenEvent.MOTION_FINISH, transition_end);
}
private function transition_render(event:TweenEvent): void
{
canvas.copyPixels((goingBack ? toScreen : fromScreen), new Rectangle(currentX, 0, stage.width - currentX, stage.height), zeroPoint);
canvas.copyPixels((goingBack ? fromScreen : toScreen), canvas.rect, new Point(stage.width - currentX, 0));
}
private function transition_end(event:TweenEvent): void
{
slideAni.removeEventListener(TweenEvent.MOTION_FINISH, transition_end);
slideAni.removeEventListener(TweenEvent.MOTION_CHANGE, transition_render);
slideAni = null;
removeChild(canvasBitmap);
goingBack = false;
}
public function screenCapture(bd:BitmapData, dispObj:DisplayObject):void
{
bd.fillRect(bd.rect, Settings.appBackgroundColor);
bd.draw(dispObj);
}
The above code may be missing some stuff, but it's just so you get the idea.
This works fine in the PC, but in the iPad 2 the animation is quite jerky in both CPU and GPU modes.
Isn't blitting supposed to be very fast because it's just copying pixels in a canvas instead of moving actual displayobjects?
This animation is not smooth at all.
I've seen Flex has some transition animations: http://devgirl.org/2011/05/12/flex-4-5-using-mobile-view-transitions/
Is it possible to use them in a regular AIR project?
