iOS: change between high and low dpi at runtime

As the title says, i was wondering if it’s possible to change between retina and non-retina window at runtime.

If it is, then how is the best / correct way to do it?

Thanks!

We currently enable this only when the window is first created. You could override the default ApplicationMain.hx for Lime in order to make it occur based on some bit of logic, but generally you would either choose low DPI, or use high DPI, but scale up to use the same dimensions of low DPI at the higher resolution. You want to expose it as a setting?

Hi Josh, thanks for the quick reply :slight_smile:

I’m supporting a wide range of devices currently, from iPad 2 to iPad Pro, and i just noticed that despite all our optimizations, the game crashes when running with retina on iPad 3. Turning it off (thus reverting from 2048x1536 back to 1024x768) solves the problem. So i need to be able to detect user device and change to low-dpi / non-retina when an iPad 3 is detected.

I’d probably do it right at the beginning of main, just so i can detect device model (which i plan to do through native extension since i’m using 3.6.1 / 2.9.1 and these features are not present in those versions).

In current releases we set the value here:

https://github.com/openfl/openfl/blob/develop/templates/haxe/ApplicationMain.hx#L38

It may require some source manipulation for older releases, but it may be possible to detect the device version and change the value before the window is created.

1 Like

Thanks, i’m gonna try to check values before window creation and try changing the setting based on that.

I’ll post the steps here later in case i succeed.

@singmajesty I altered Lime and OpenFL templates to include allowHighDPI in window config, but strangely it doesn’t appear to be reading the values from project.xml. This is the generated ApplicationMain.hx:

windows: [
	
	{
		allowHighDPI: null,
		antialiasing: 0,
		background: 0,
		borderless: false,
		depthBuffer: false,
		display: 0,
		fullscreen: false,
		hardware: true,
		height: 900,
		parameters: "{}",
		resizable: true,
		stencilBuffer: true,
		title: "Test Project",
		vsync: true,
		width: 1600,
		x: null,
		y: null
	},
]

This is how i’m trying to set it through xml:

	<window width="0" height="0" if="mobile" />
	<window width="1600" height="900" if="desktop" />
	<window fps="30" background="#000000" hardware="true" vsync="true" />
	<window allow-shaders="true" require-shaders="true" if="cpp"/>
	<window allow-high-dpi="true" />

Is there any other class which must be changed for this to work?

Thanks! :slight_smile:

It may be because of Lime 2.9.1, I think <window allow-high-d-p-i="true" /> worked in some older versions (due to a parser bug), or perhaps it’s older than the allowHighDPI flag

Tried changing code in ProjectXMLParser.hx to consider many cases, but no dice:

//case "allow-high-dpi":
case "allow-high-dpi", "allow-high-d-p-i", "allowHighDpi", "allowHighDPI", "allowhighdpi", "AllowHighDpi", "AllowHighDPI":
	
	if (Reflect.hasField (windows[id], name)) {
		Reflect.setField (windows[id], name, Std.string(value) == "true");
	}

Unfortunately stage.window.config.allowHighDPI continues to appear as null. Is there any other thing i could try?

Did you lime rebuild tools after making the changes?

You could also ignore the window XML, since you want it at runtime anyway, use your own logic in the ApplicationMain class to set it to true or false

Yeah, i was trying to make it all work but you’re right, it’s not necessary. I’m leaving the project.xml part out and changed ApplicationMain which works as expected.

Thanks for the help Josh! :slight_smile:

1 Like