如何提高Mac上光栅滚动的性能?

时间:2010-02-25 14:29:34

标签: flex macos raster

我有一个带有大栅格地图的游戏

现在我们正在使用jpeg(4900x4200)

在游戏中我们需要滚动浏览此地图。

我们使用以下内容:

Class Map扩展了mx.containers.Canvas

和mx.controls.Image就可以了

在构造函数中,我们有:

public function Map() {
        super();
        image.source = ResourceManager.interactiveManager.map;//big image
        addChild(image);
......
}

滚动我们使用:

    if(parentAsCanvas==null){
        parentAsCanvas = (parent as Canvas);
    }

    parentAsCanvas.verticalScrollPosition = newX;
    parentAsCanvas.horizontalScrollPosition = newY;

在Windows中,我们有非常好的表现。 在Linux和Mac的flashplayer中,我们也有很好的表现。

但在浏览器中性能相当慢! 我们可以做些什么来解决它?

2 个答案:

答案 0 :(得分:3)

它很慢,因为你一直在渲染一个大图像。

以下是我想到的一些事情:

  • 尝试使用包含图像BitmapData的Bimtap对象中的scrollRect属性来显示可见区域,然后使用scrollRect x和y移动到新区域
  • 尝试使用可视区域大小的BitmapData,并使用copyPixels()来显示正确的区域,再次使用矩形
  • 尝试使用BitmapData.scroll()

以下是几个片段:

scrollRect的:

//assuming map is BitmapData containing your large image
//100x100 is a test scroll area
var scroll:Rectangle = new Rectangle(0,0,100,100);
var bitmap:Bitmap = new Bitmap(map);
bitmap.scrollRect = scroll;
addChild(bitmap);

this.addEventListener(Event.ENTER_FRAME, update);
function update(event:Event):void{
    scroll.x = mouseX;
    scroll.y = mouseY;
    bitmap.scrollRect = scroll;
}

copyPixels:

var scroll:Rectangle = new Rectangle(0,0,100,100);
var scrollPoint:Point = new Point();
var map:BitmapData = new Map(0,0);
var bitmap:Bitmap = new Bitmap(new BitmapData(100,100,false));
bitmap.bitmapData.copyPixels(map,scroll,scrollPoint);
addChild(bitmap);

this.addEventListener(Event.ENTER_FRAME, update);
function update(event:Event):void{
    scroll.x = mouseX;
    scroll.y = mouseY;
    bitmap.bitmapData.fillRect(scroll,0xFFFFFF);
    bitmap.bitmapData.copyPixels(map,scroll,scrollPoint);
}

不完美,但它应该给你一个想法

HTH, 乔治

答案 1 :(得分:0)

我已阅读以下内容http://www.insideria.com/2008/04/flex-ria-performance-considera.html

我和我找到了解决问题的方法。

如果我在浏览器中以“http://host/myswf.swf”打开我的SWF,那么我在浏览器中会失去巨大的性能,因为LaoyoutManager会重新计算应用程序中所有画布的位置和大小。它的过程占据了60%以上的性能。(是的,我们的应用程序中有很多画布)。

当我把我的应用程序放在html页面中的大小不一的html块中时,所有问题都消失了!我的性能提升了80%!