我在flash(带有flex)中做了一点game,其中一张随机图片(2个atm)被剪切掉然后用于十五个拼图,它运作得很好。我遇到的问题是当我将large version上传到例如deviantArt它没有正确调整大小。 我意识到这是由于我一般使用位图组件和尺寸的固定值,但整个尺度和相对尺寸现在有点压倒性。
所以问题是:我如何(容易?最好?)制作位图组件 - 甚至可能是按钮 - 与应用程序一起调整大小/重新缩放而不会丢失宽高比和(相对)空格? / p>
这是.mxml:
中的相关代码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;
}
}
}