我遇到了 AS3 和 AIR 的问题。我正在为带有飞机的智能手机开发横向滚动游戏,我使用不同的背景作为图层。
最重要的是:我使用 GPU 并且只使用位图,质量设置为低。所以性能设置都是为智能手机使用而设置的。
我使用绘图 API 将它们放入一个矩形中,并使用矩阵移动背景:
protected var scrollingBitmap:BitmapData;
protected var canvas:Graphics;
protected var matrix:Matrix;
public function move(dx:Number, dy:Number):void {
matrix.translate(dx, dy);
if(dx != 0) matrix.tx %= scrollingBitmap.width;
if(dy != 0) matrix.ty %= scrollingBitmap.height;
drawCanvas();
}
protected function drawCanvas():void {
canvas.clear();
canvas.beginBitmapFill(scrollingBitmap, matrix, true, true);
canvas.drawRect(0, -scrollingBitmap.height, 1404, scrollingBitmap.height);
}
更新2(
看看这个: http: //plasticsturgeon.com/2010/06/infinite-scrolling-bitmap-backgrounds-in-as3/
我用它来创建我的背景。
有了这个,我可以模拟我的飞机在不移动整个背景的情况下向右飞行,我可以使用一个每次重复的小图形(对于前景层)。
对于背景层,我也使用这种方法,但图形要大得多,而且我只以较低的飞机速度移动它来模拟远处的背景。
我的移动方法是在一个 enterframe 事件上。所以我可以用我的飞机的“运动”来更新每一帧的背景。
)
平面可以超过位图的高度。每次位图回到窗口/屏幕时,都会发生真正的长时间滞后。当飞机飞得很快时,游戏也开始滞后。
我的第一种方法是使用 .PNG 文件(但它们非常大:1-3MB 大小)。我的下一个方法是使用 .GIF 文件(大小要小得多)。
两者都是一样的。所以不可能是这样。
我阅读了有关 draw() 和 copyPixels() 的信息,但我不知道如何使用它们来重复图像。
更新1:
protected var scrollingBitmap:BitmapData;
protected var canvas:Bitmap;
protected function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
canvas = new Bitmap(new BitmapData(1404, scrollingBitmap.height, true), "auto", true);
this.addChild(canvas);
drawCanvas();
}
public function move(dx:Number, dy:Number):void {
if(dx != 0) dx %= scrollingBitmap.width;
if(dy != 0) dy %= scrollingBitmap.height;
drawCanvas(dx, dy);
}
protected function drawCanvas(xPos:Number = 0, yPos:Number = 0):void {
canvas.bitmapData.copyPixels(scrollingBitmap, new Rectangle(0, 0, 1404, scrollingBitmap.height), new Point(xPos, yPos), scrollingBitmap);
}