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

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.

主站蜘蛛池模板: 雷州市| 聊城市| 社会| 广汉市| 宣威市| 佛山市| 京山县| 拉萨市| 河池市| 德清县| 临潭县| 西林县| 和林格尔县| 蒲城县| 吉安市| 宁武县| 怀集县| 手游| 鄱阳县| 旺苍县| 鄯善县| 政和县| 重庆市| 龙江县| 应城市| 乐至县| 曲周县| 徐州市| 遂昌县| 宣汉县| 神木县| 甘洛县| 丹棱县| 普宁市| 宁南县| 贺州市| 阳朔县| 桐梓县| 仁寿县| 连江县| 阳谷县|