[SOLVED] Screen Scale Detection

Hello friends.

Windows 10 has the option of scale in addition to resolution. So even if you use 1080p resolution, you can make the buttons and icons appear larger by using 150% scale. This is not good for Armory’s browser export. Even if you make it full screen, you can never go full screen on a phone, tablet and any other scaled screen other than 100%. Is there a solution to this?

Thanks.

1 Like

Hi, you can get this information via kha.Display.pixelsPerInch in Haxe:

kha.Display.primary.pixelsPerInch; // For the primary display

kha.Display.all[displayIndex].pixelsPerInch; // For a specific display with index displayIndex

I don’t think it’s exposed via logic nodes. I think we should add this to the Get Display Resolution node.

I don’t know whether this attribute is properly implemented on all platforms, I tested it on Krom for Windows and got 96 and 120 as results for 100% and 125% display scaling.

2 Likes

I think we don’t need this node. Instead, a code can be added that constantly automatically arranges it.
However, adding nodes may also be a good idea, as some developers may want to be able to control this.

Armory always exports 100% scale projects.

Maybe this is works:

set(Project Screen Ratio on the Browser) = get(Export Project Screen Ratio) x get(Windows Screen Scale Ratio)

you are amazing dude. can you write this code? I’ve worked on this situation(very long time). you have found the solution. I spend effort on index.html actually that’s pointless and that’s the point you found it. thank you.

how to add this fix to the project?

Thanks but I’m not good on HAXE.

Edit: I tried some codes. It didn’t work but we can improve it.

import openfl.display.Stage;
import kha.Display.pixelsPerInch;

class Main {
  static function main() {
    var screenW:Int = Std.int(stage.stageWidth);
    var screenH:Int = Std.int(stage.stageHeight);
    
    var scale:Float = Math.min(screenW / TARGET_WIDTH, screenH / TARGET_HEIGHT);
    
    stage.scaleMode = StageScaleMode.FULL_SCREEN;
    stage.stageWidth = TARGET_WIDTH * scale;
    stage.stageHeight = TARGET_HEIGHT * scale;
  }
}