Adobe AIR Stage.contentsScaleFactor always 1 on iPhone4s and iPad mini

My application is just an AIR Mobile AS3 project from FlashDevelop: application.xml file and main class.

In the main class, I am creating a textbox with the value stage.contentsScaleFactor

as text after the first one Event.RESIZE

:

var textField:TextField = new TextField();
textField.appendText("Size: " + stage.stageWidth + " x " + stage.stageHeight + "\n");
textField.appendText("Scale: " + stage.contentsScaleFactor + "\n");
addChild(textField);

      

On my retina-enabled iPhone, I get

Size: 960 x 640

Scale: 1

for

<requestedDisplayResolution>high</requestedDisplayResolution>

      

and

Size: 480 x 320

Scale: 1

for

<requestedDisplayResolution>standard</requestedDisplayResolution>.

      

Almost the same for iPad.

Size: 2048 x 1536

Scale: 1

for tall and

Size: 1024 x 768

Scale: 1

for the standard.

I compile with the latest AIR SDK 18.0.0.142 (beta) -swf-version=29

. Same results for AIR SDK 18 release.

For the AIR 14 SDK and -swf-version=25

I am getting some garbage values ​​for the size (it looks like my width and height swf multiplied by what it should be contentsScaleFactor

), but still 1

for contentsScaleFactor

.

Edit: I came across various questions that have been mentioned contentsScaleFactor

over the net (like this one ). They claim there contentsScaleFactor

should be 2 on a Retina display This property is described as follows:

Determines the effective scaling factor for pixels in the scene. This value is usually 1 on standard screens and 2 on HiDPI (aka Retina) screens. When this scene is displayed on HiDPI screens, the pixel is doubled; even if the scene scaling mode is set to StageScaleMode.NO_SCALE. Stage.stageWidth and Stage.stageHeight continue to be reported in classic pixel units. Note: this value can change dynamically if the rung is on HiDPI or standard screen.

Besides,

<requestedDisplayResolution>standard</requestedDisplayResolution>

      

and configureBackBuffer

with wantsBestResolution

set to true

, I still get a 1024 * 768 buffer on the iPad. I made sure that when drawing a clear 256 * 256 texture on a 128 * 128 quad, the result is blurry. Then I do the same with

<requestedDisplayResolution>high</requestedDisplayResolution>

      

I get a clear image of the same physical size.

My current questions:

  • Is contentsScaleFactor

    2 on Retina iPad / iPhone? If so, are there any compiler / packer options that I am missing?
  • How can I determine for requestedDisplayResolution=standard

    what my stage has been scaled?
  • And if it contentsScaleFactor

    doesn't work on mobile devices, for what purpose is this property? Should it work, for example, on a Mac with a Retina display?

Edit 2:

contentsScaleFactor

Works great on Mac with Retina display , reports 2

.

+3


source to share


3 answers


Use Capability.screenDPI to get DPI ratio, divide stage.stageWidth by screenDPI. On an iPad you get about 8 (one DPI unit = about 2 real estate fingers), DPI gives you your density. Now compare both, non-mesh iPad = 8 DPI for 132 pixels / DPI, retina iPad = 8 DPI for 264 pixels / DPI (HD), etc.



+1


source


From comments:

Yes, this is how I am doing it now for IOS devices, but unfortunately Capability.screenDPI is generally unreliable. Always on 72 desktop, some "random" values ​​on android and don't take DPI current events counter

It might not be so much Dots Per Inch as what you want, but instead you're looking for Pixels Per Inch ? DPI is used when printing as ink dots on paper. PPI stands for number of pixels versus real inch. Don't worry, even the Wikipedia article admits: "... it has become customary to refer to PPI as DPI , although PPI refers to input resolution " (now we understand that DPI is print resolution )



This means that you should forget Capability.screenDPI

and instead start including Capabilities.screenResolutionX

(display width) and Capabilities.screenResolutionY

(display height) numbers in your calculations .

Here is the code for the feedback. Hope you find this helpful: PS: Double check the Flash traces using a ruler against the computer screen.

var scrn_W : uint = Capabilities.screenResolutionX;
var scrn_H : uint = Capabilities.screenResolutionY;
var scrn_DPI : uint = Capabilities.screenDPI;

var init_stageW : int = stage.stageWidth; var init_stageH : int = stage.stageHeight;

//Diagonal in Pixels
var scrn_Dg_Pix : Number = int( Math.sqrt( scrn_W * scrn_W + scrn_H * scrn_H ) );

//Diagonal in Inches
var scrn_Diag : Number = int( Math.sqrt( scrn_W * scrn_W + scrn_H * scrn_H ) ) / 100;

var scrn_PPI : uint = int( Math.sqrt( scrn_W * scrn_W + scrn_H * scrn_H ) ) / scrn_Diag;
//or scrn_PPI = scrn_Dg_Pix / scrn_Diag; //gives same result as above line of code

var dot_Pitch : Number = scrn_W / ( Math.sqrt( scrn_W * scrn_W + scrn_H * scrn_H ) ) / (scrn_Diag * 25.4) / scrn_W;

var scrn_Inch_W : Number = ( scrn_W / scrn_PPI ); var scrn_Inch_H : Number = ( scrn_H / scrn_PPI );

var result_Num : Number = 0; var temp_Pix_Num:Number = 0;
var testInch : Number = 0; var my_PixWidth : Number = 0; 

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeListener);  //just in case 


////////////////////
//// FUNCTIONS

function inch_toPixels( in_Num : Number) : Number
{
    temp_Pix_Num = in_Num;
    result_Num = scrn_PPI * temp_Pix_Num;
    return result_Num; 
}

function pixels_toInch( in_Num : Number) : Number
{
    temp_Pix_Num = in_Num;  
    result_Num =  temp_Pix_Num / scrn_PPI;
    return result_Num; 
}

function cm_toInch( in_CM : Number) : Number
{
    //inch = cm * 0.393700787; //from centimetre to inch
    result_Num = in_CM * 0.393700787; return result_Num; 
}

function inch_toCM( in_Inch : Number) : Number
{
    //cm = inch * 2.54; //from inch to centimetre
    result_Num = in_Inch * 2.54; return result_Num;
}


function resizeListener (e:Event):void 
{ 
    // Handle Stage resize here (ie. app window Scale Drag / Minimize etc)
    //trace("new stageWidth: " + stage.stageWidth + " new stageHeight: " + stage.stageHeight);
}

///////////////
//// TRACES

trace("Stage Init Width  : " + init_stageW);
trace("Stage Init Height : " + init_stageH);

trace("Screen Width     : " + scrn_W);
trace("Screen Height    : " + scrn_H);
trace("Screen DPI       : " + scrn_DPI);
trace("Screen PPI       : " + scrn_PPI);

trace("Screen Diag      : " + scrn_Diag);
trace("Screen Diag Pix  : " + scrn_Dg_Pix);

trace("Dot Pitch        : " + dot_Pitch);
trace("Disp Width (inches)  : " + scrn_Inch_W );
trace("Disp Height (inches) : " + scrn_Inch_H );

      

+1


source


How do I use Application.applicationDPI and Application.runtimeDPI to calculate the actual scale factor?

0


source







All Articles