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

Optimize your display images

It's important to optimize your image file size as much as you can. Using full-screen images can impact the performance of your application. They require more time to load on a device and consume a lot of texture memory. When a lot of memory is consumed in an application, in most cases it'll be forced to quit.

The iOS devices vary in the size of their available memory, depending on which one you have out of the following:

  • iPhone 3GS, iPad, and iTouch 3G/4G of 256 MB RAM
  • iPhone 4/4S, iPad 2, iPad Mini, and iTouch 5G of 512 MB RAM
  • iPhone 5/5S/6, 6 Plus, iPad 3G, and iPad 4G of 1 GB RAM

For example, texture memory on the iPhone 3GS should be kept under 25 MB before performance issues start occurring by slowing down your app or even forcing it to quit. An iPad 2 would have no problem going farther down that boundary since it has more memory available.

Note

Refer to http://docs.coronalabs.com/api/event/memoryWarning/index.html to apply memory warnings for iOS devices.

For Android devices, there is around a 24 MB memory limit. So, it's important to be aware of how many display objects you have in your scene and how to manage them when they are not needed in your app any more.

In cases when you no longer need an image to be displayed on screen, use the following code:

image.parent:remove( image ) -- remove image from hierarchy

Alternatively, you can also use this line of code:

image:removeSelf( ) -- same as above

If you want to remove an image from the scene completely throughout the lifetime of your app, include the following line after your image.parent:remove( image ) or image:removeSelf() code:

image = nil

Keeping memory usage low within your application will prevent crashes and improve performance. For more information on optimization, go to http://developer.coronalabs.com/content/performance-and-optimization.

Pop quiz – basics of Lua

Q1. Which of the following are values?

  1. Numbers
  2. nil
  3. Strings
  4. All of the above

Q2. Which relational operator is false?

  1. print(0 == 0)
  2. print(3 >= 2)
  3. print(2 ~= 2)
  4. print(0 ~= 2)

Q3. What is the correct way to scale an object in the x direction?

  1. object.scaleX
  2. object.xscale
  3. object.Xscale
  4. object.xScale
主站蜘蛛池模板: 东港市| 甘洛县| 乳源| 伊通| 昌乐县| 尚义县| 蒙山县| 杭锦旗| 永城市| 北川| 九江市| 冕宁县| 仪陇县| 华阴市| 迁安市| 常山县| 浙江省| 北海市| 大理市| 博野县| 江阴市| 崇信县| 屏东市| 辽源市| 盐城市| 德惠市| 牙克石市| 集安市| 石泉县| 成都市| 新郑市| 潜山县| 福清市| 开化县| 孟村| 德江县| 伊吾县| 宣汉县| 舞阳县| 阿图什市| 罗甸县|