AS3用正方形(居中)填充可用屏幕区域
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3用正方形(居中)填充可用屏幕区域相关的知识,希望对你有一定的参考价值。
Taken from Christian Cantrell's Adobe article called 'Authoring mobile Flash content for multiple screen sizes'.
// Display as many blocks on the screen as will fit var BLOCK_SIZE:Number = 1; var BLOCK_BUFFER:uint = 3; var blockSize:uint = this.inchesToPixels(BLOCK_SIZE); var blockTotal:uint = blockSize + BLOCK_BUFFER; var cols:uint = Math.floor(this.stage.stageWidth / blockTotal); var rows:uint = Math.floor((this.stage.stageHeight) / blockTotal); var blockXStart:uint = (this.stage.stageWidth - ((cols * blockSize) + ((cols - 1) * BLOCK_BUFFER))) / 2; var blockX:uint = blockXStart; var blockY:uint = ((this.stage.stageHeight) - ((rows * blockSize) + ((rows - 1) * BLOCK_BUFFER))) / 2; for (var colIndex:uint = 0; colIndex < rows; ++colIndex) { for (var rowIndex:uint = 0; rowIndex < cols; ++rowIndex) { var block:Sprite = this.getBlock(blockSize); block.x = blockX; block.y = blockY; this.addChild(block); blockX += blockTotal; } blockY += blockTotal; blockX = blockXStart; } function getBlock(blockSize:uint):Sprite { var block:Sprite = new Sprite(); block.graphics.beginFill(0xAAC228); block.graphics.drawRect(0, 0, blockSize, blockSize); block.graphics.endFill(); block.cacheAsBitmap = true; return block; } function inchesToPixels(inches:Number):uint { return Math.round(Capabilities.screenDPI * inches); }
以上是关于AS3用正方形(居中)填充可用屏幕区域的主要内容,如果未能解决你的问题,请参考以下文章
如何在 3.5 英寸和 4 英寸 iPhone 屏幕上显示图像时如何居中?