官术网_书友最值得收藏!

Time for action – scaling display objects on multiple devices

In our Display Objects project, we left off displaying a background image and three similar display objects in the simulator. When running the project on different devices, the coordinates and resolution size were most compatible with the iPhone only. When building applications for multiple devices across iOS and Android platforms, we can configure it using a config.lua file that is compiled into the project and accessed at runtime. So let's get to it!

  1. In your text editor, create a new file and write out the following lines:
    application =
    {
      content =
      {
        width = 320,
        height = 480,
        scale = "letterbox",
        xAlign = "left",
        yAlign = "top"
      },
    }
  2. Save your script as config.lua in your Display Objects project folder.
  3. For Mac users, launch your application in Corona under the iPhone device. Once you have done so, under the Corona Simulator menu bar, go to Window | View As | iPhone 4. You will notice that the display objects fit perfectly on the screen and that there are no empty black spaces showing either.
  4. Windows users, launch your application in Corona under the Droid device. You will notice that all the content is scaled and aligned properly. Under the Corona Simulator menu bar, go to Window | View As | NexusOne. Observe the similarities in the content placement to that of the Droid. In the following screenshot, from left to right, you can see the iPhone 3GS, iPhone 4, Droid, and NexusOne:
    Time for action – scaling display objects on multiple devices

What just happened?

You have now learned a way to implement an easy configuration to display your content across a variety of devices on iOS and Android. Content scaling features are useful for multiscreen development. If you look in the config.lua file we created, width = 320 and height = 480. This is the resolution size that the content is originally authored for. In this case, it is the iPhone 3G. Since we used scale = "letterbox", it enabled the content to uniformly scale up as much as possible while still showing the entire content on the screen.

We also set xAlign = "left" and yAlign = "top". This fills in the empty black screen space that shows on the Droid specifically. The content scaling is at the center by default, so aligning the content to the left and top of the screen will take away the additional screen space.

主站蜘蛛池模板: 丹江口市| 南安市| 合川市| 丹江口市| 裕民县| 会泽县| 来安县| 澎湖县| 铜陵市| 克拉玛依市| 晋州市| 连城县| 舒城县| 什邡市| 搜索| 宜黄县| 营山县| 通渭县| 彭水| 闻喜县| 那曲县| 青铜峡市| 临汾市| 本溪市| 泗洪县| 浙江省| 大同市| 宜川县| 略阳县| 南雄市| 德安县| 辽阳县| 岑巩县| 射洪县| 蒙城县| 遂川县| 嘉荫县| 汤原县| 富宁县| 开封市| 高阳县|