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

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.

主站蜘蛛池模板: 安庆市| 北京市| 灵山县| 南陵县| 汕头市| 三原县| 德惠市| 车致| 唐山市| 德令哈市| 河北省| 清水县| 普定县| 龙里县| 广州市| 玉山县| 木兰县| 库尔勒市| 叶城县| 门源| 遂溪县| 额尔古纳市| 馆陶县| 保山市| 山东省| 海宁市| 伊宁县| 明水县| 巫山县| 宽城| 新宁县| 平武县| 花莲市| 安庆市| 宣武区| 集安市| 莒南县| 措美县| 金寨县| 台山市| 荔浦县|