scrollRect のパフォーマンスを向上させるには、ベクターをビットマップとしてキャッシュする必要があります。そうしないと、scrollRect のパフォーマンスが低下するだけのマスクになります (情報ソース)。
ただし、cacheAsBitmap を適用すると、オブジェクト/scrollRect を移動できないようです。なぜ?
package
{
//Imports
import flash.display.Screen;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
//Class
[SWF(width = "800", height = "500", backgroundColor = "0x444444")]
public class ScrollRectTest extends Sprite
{
//Variables
private var background:Sprite;
private var ball:Sprite;
private var newScrollRect:Rectangle;
//Constructor
public function ScrollRectTest()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = 60;
init();
}
//Initialize
private function init():void
{
background = new Sprite();
background.graphics.beginFill(0x000000, 1.0);
background.graphics.drawRect(0, 0, 200, 400);
background.graphics.endFill();
ball = new Sprite();
ball.graphics.beginFill(0xFF0000, 1.0);
ball.graphics.drawCircle(0, 0, 100);
ball.graphics.endFill();
//ball.cacheAsBitmap = true; //<-- uncomment this
ball.scrollRect = new Rectangle(background.x, background.y, background.width, background.height);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownEventHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpEventHandler);
addChild(background);
addChild(ball);
}
//Mouse Down Event Handler
private function mouseDownEventHandler(evt:MouseEvent):void
{
addEventListener(Event.ENTER_FRAME, enterFrameEventHandler);
}
//Mouse Up Event Handler
private function mouseUpEventHandler(evt:MouseEvent):void
{
removeEventListener(Event.ENTER_FRAME, enterFrameEventHandler);
}
//Enter Frame Event Handler
private function enterFrameEventHandler(evt:Event):void
{
newScrollRect = ball.scrollRect;
newScrollRect.y -= 10;
newScrollRect.x -= 5;
ball.scrollRect = newScrollRect;
}
}
}