×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2013.1115 | Released: 18 May 2013, 2:04am | What's New | Download Now

display.contentScaleX

Description:

The ratio between content pixel and screen pixel width.

This value will always be 1 unless your project's config.lua file specifies your content's height and width (see example below). Different scale modes (letterbox, zoomEven, and so forth) will result in different scale factors.

Syntax:

scalex = display.contentScaleX

Example:

-- main.lua
scalex = display.contentScaleX
scaley = display.contentScaleY
-- display scale values
print("scalex", "scaley", scalex, scaley)

-- config.lua
application =
        {
                content =
                {
                        width = 320,
                        height = 480,
                        scale = "letterbox"
                },
 }                       

Sample output on various devices:

-- iPhone
scale_x scale_y 1       1
 
-- iPhone 4
scale_x scale_y 0.5     0.5
 
-- Droid
scale_x scale_y 0.66666668653488        0.66666668653488
 
-- iPad
scale_x scale_y 0.46875 0.46875

Parameters:

 

Returns:

The ratio between content pixel and screen pixel width.

Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Build 2010.243
  • Windows:
    Build 2010.243
  • iOS:
    Build 2010.243
  • Android:
    Build 2010.243

Replies

berrygp
User offline. Last seen 2 weeks 20 hours ago. Offline
Joined: 25 Jan 2011

Documentation needs to be updated.

Print statement shows: print("scalex", "scaley", scalex, scaley)

But output shows: scale_x scale_y 1 1

In output "scale_x" should be "scalex" and "scale_y" should be "scaley"

Tom
User offline. Last seen 5 hours 52 min ago. Offline
Staff
Joined: 13 Jul 2010

Thanks, we will make the changes on our new API docs page.
http://docs.coronalabs.com

These API pages are no longer valid.