1

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

现在我们使用 jpeg (4900x4200)

在游戏过程中,我们需要滚动浏览这张地图。

我们使用以下内容:

类映射扩展 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 中我们也有很好的表现。

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

4

2 回答 2

3

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

以下是我脑海中闪过的几件事:

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

以下是一些片段:

滚动矩形:

//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;
}

复制像素:

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,乔治

于 2010-02-25T14:47:50.513 回答
0

我已经阅读了以下文章http://www.insideria.com/2008/04/flex-ria-performance-considera.html

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

如果我在浏览器中以“ http://host/myswf.swf ”的形式打开我的 SWF,我会在浏览器中损失巨大的性能,因为工作 LayoutManager 会重新计算应用程序中所有画布的位置和大小。它处理了超过 60% 的性能容量。(是的,我们的应用程序中有很多画布)。

当我将我的应用程序放在 html 页面中的 contant-size html 块中时,所有问题都消失了!我的性能提升了 80%!

于 2010-03-16T10:21:57.987 回答