AS3用正方形(居中)填充可用屏幕区域

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3用正方形(居中)填充可用屏幕区域相关的知识,希望对你有一定的参考价值。

Taken from Christian Cantrell's Adobe article called 'Authoring mobile Flash content for multiple screen sizes'.
  1. // Display as many blocks on the screen as will fit
  2. var BLOCK_SIZE:Number = 1;
  3. var BLOCK_BUFFER:uint = 3;
  4. var blockSize:uint = this.inchesToPixels(BLOCK_SIZE);
  5. var blockTotal:uint = blockSize + BLOCK_BUFFER;
  6. var cols:uint = Math.floor(this.stage.stageWidth / blockTotal);
  7. var rows:uint = Math.floor((this.stage.stageHeight) / blockTotal);
  8. var blockXStart:uint = (this.stage.stageWidth - ((cols * blockSize) + ((cols - 1) * BLOCK_BUFFER))) / 2;
  9. var blockX:uint = blockXStart;
  10. var blockY:uint = ((this.stage.stageHeight) - ((rows * blockSize) + ((rows - 1) * BLOCK_BUFFER))) / 2;
  11. for (var colIndex:uint = 0; colIndex < rows; ++colIndex) {
  12. for (var rowIndex:uint = 0; rowIndex < cols; ++rowIndex) {
  13. var block:Sprite = this.getBlock(blockSize);
  14. block.x = blockX;
  15. block.y = blockY;
  16. this.addChild(block);
  17. blockX += blockTotal;
  18. }
  19. blockY += blockTotal;
  20. blockX = blockXStart;
  21. }
  22.  
  23. function getBlock(blockSize:uint):Sprite
  24. {
  25. var block:Sprite = new Sprite();
  26. block.graphics.beginFill(0xAAC228);
  27. block.graphics.drawRect(0, 0, blockSize, blockSize);
  28. block.graphics.endFill();
  29. block.cacheAsBitmap = true;
  30. return block;
  31. }
  32.  
  33. function inchesToPixels(inches:Number):uint
  34. {
  35. return Math.round(Capabilities.screenDPI * inches);
  36. }

以上是关于AS3用正方形(居中)填充可用屏幕区域的主要内容,如果未能解决你的问题,请参考以下文章

AS3绘制正方形模糊和渐变填充

如何在 3.5 英寸和 4 英寸 iPhone 屏幕上显示图像时如何居中?

垂直居中内容区域直到达到一定高度?

用中心方形组件填充柔性容器

居中时如何“自动扩展”CSS网格单元以填充可用空间? [复制]

垂直居中问题[重复]