如何使flash游戏中的(位图)组件正确调整大小
我在flash(使用flex)中制作了一个小程序,其中一张随机图片(从2个atm机中)被切碎,然后用于15个拼图,效果很好。我遇到的问题是,当我上传到例如DeviceArt时,它的大小没有正确调整。 我意识到这是因为我通常使用位图组件和尺寸的固定值,但是整体比例和相对大小现在有点难以承受 所以问题是:如何(轻松?最佳?)使位图组件,甚至按钮,与应用程序一起调整大小/重新缩放,而不丢失宽高比和(相对)空间 以下是.mxml中的相关代码:如何使flash游戏中的(位图)组件正确调整大小,flash,bitmap,resize,components,tiles-game,Flash,Bitmap,Resize,Components,Tiles Game,我在flash(使用flex)中制作了一个小程序,其中一张随机图片(从2个atm机中)被切碎,然后用于15个拼图,效果很好。我遇到的问题是,当我上传到例如DeviceArt时,它的大小没有正确调整。 我意识到这是因为我通常使用位图组件和尺寸的固定值,但是整体比例和相对大小现在有点难以承受 所以问题是:如何(轻松?最佳?)使位图组件,甚至按钮,与应用程序一起调整大小/重新缩放,而不丢失宽高比和(相对)空间 以下是.mxml中的相关代码: public function init():void {
public function init():void
{
//!!!WARNING!!!
//This part has to be updated manually when more/different pictures are embedded.
if (PICS_ARE_EMBEDDED)
{
var pic1:BitmapAsset = new img1() as BitmapAsset;
var pic2:BitmapAsset = new img2() as BitmapAsset;
this.pics.push(pic1);
this.pics.push(pic2);
}
this.tiles = new Vector.<Tile>();
this.positions = new Vector.<Position>();
var currentNumber:int = 1;
//Creation of the tiles and positions.
for (var i:int = 0; i < TILES_PER_SIDE; i++)
{
for (var j:int = 0; j < TILES_PER_SIDE; j++)
{
var tile:Tile = new Tile(j * TILE_SIDE_LENGTH, i * TILE_SIDE_LENGTH, currentNumber);
this.tiles.push(tile);
tile.addEventListener("click", onTileClick);
var position:Position = new components.Position(j * TILE_SIDE_LENGTH, i * TILE_SIDE_LENGTH, i + 1, currentNumber);
this.positions.push(position);
tile.homePosition = position;
if (currentNumber % TILES_PER_SIDE != 1)
{
var pos1:Position;
(pos1 = this.positions[currentNumber - 2]).neighbours.push(position);
position.neighbours.push(pos1);
}
if (currentNumber > TILES_PER_SIDE)
{
var pos2:Position;
(pos2 = this.positions[(currentNumber - TILES_PER_SIDE - 1)]).neighbours.push(position);
position.neighbours.push(pos2);
}
currentNumber++;
}
}
this.switchToGame();
}
public function prepareEmbeddedPic():void
{
var nextPicNumber:int = Math.floor(Math.random() * this.pics.length);
if (this.picNumber != nextPicNumber)
{
this.picNumber = nextPicNumber;
this.image = this.pics[this.picNumber].bitmapData;
for each (var t:Tile in this.tiles)
{
var ba:ByteArray = this.image.getPixels(new Rectangle(t.homeX, t.homeY, TILE_SIDE_LENGTH, TILE_SIDE_LENGTH));
ba.position = 0;
var bmd:BitmapData;
(bmd = new BitmapData(TILE_SIDE_LENGTH, TILE_SIDE_LENGTH, false)).setPixels(new Rectangle(0, 0, TILE_SIDE_LENGTH, TILE_SIDE_LENGTH), ba);
t.img.bitmapData = bmd;
}
}
}
公共函数init():void
{
//!!!警告!!!
//嵌入更多/不同图片时,必须手动更新此部分。
if(嵌入图片)
{
var pic1:BitmapAsset=new img1()作为BitmapAsset;
var pic2:BitmapAsset=new img2()作为BitmapAsset;
此.pics.push(pic1);
此.pics.push(pic2);
}
this.tiles=新向量。();
this.positions=新向量。();
var currentNumber:int=1;
//创建瓷砖和位置。
对于(变量i:int=0;i每侧平铺)
{
var pos2:位置;
(位置2=此。位置[(当前编号-每侧瓷砖-1)])。邻接。推(位置);
位置。邻居。推(位置2);
}
currentNumber++;
}
}
this.switchToGame();
}
公共函数prepareEmbeddedPic():void
{
var nextPicNumber:int=Math.floor(Math.random()*this.pics.length);
if(this.picNumber!=nextPicNumber)
{
this.picNumber=nextPicNumber;
this.image=this.pics[this.picNumber].bitmapData;
对于每个(vart:this.tiles中的Tile)
{
var ba:ByteArray=this.image.getPixels(新矩形(t.homeX,t.homeY,TILE_SIDE_LENGTH,TILE_SIDE_LENGTH));
ba.position=0;
var-bmd:BitmapData;
(bmd=新位图数据(平铺边长度,平铺边长度,false)).setPixels(新矩形(0,0,平铺边长度,平铺边长度),ba);
t、 img.bitmapData=bmd;
}
}
}
我会考虑在整件事情上设置scaleMode,或者使用矩阵来调整大小。@AmyBlankenship据我所知,scaleMode在默认情况下已设置为“全部显示”,但具有固定尺寸的位图不受此影响。另一方面,矩阵(至少在这种情况下)是一个我还没有完全理解的概念。