Weird Resize Behavior on iOS


This is my first time commenting here and it’s my first openfl app. I set up a listener on stage resizing and resize my stuff accordingly. And if I change the orientation, it looks right, however many times I do it. However, it sometimes looks wrong on startup until I tilt the screen. It looks like it was drawn for the opposite orientation, then squished down to fit the orientation it’s in (e.g., if it starts in wide, it will have a miniature version of the fullscreen squished off to the side).

When I do native or neko, I don’t experience this issue. I don’t have an android to test to see if it happens on android yet.

No ideas? Okay, it looks like I described it a little wrong. It’s more like it just looks scaled down. So if I’m in landscape orientation, it starts up landscape but just way too small off to the corner. I saw in the pong tutorial that you’re supposed to wait a bit before drawing:

function added(e) {
	removeEventListener(Event.ADDED_TO_STAGE, added);
	stage.addEventListener(Event.RESIZE, resize);
	#if ios
	haxe.Timer.delay(init, 100); // iOS 6

But I tried this and it’s still starting up. I even tried increasing the timeout before it draws and still no dice. Any ideas? This is like the main bug between me being able to submit this to the app store.

I see this on iOS too. However, it fixes itself after the first RESIZE event. (Or maybe it’s the second event, I don’t know.)

Try adding this to your resize() function:

trace([stage.stageWidth, stage.stageHeight]);

What values does this print on startup? What values does it print after you rotate the device?

If I add that to my resize function, it always shows the correct value, but I also see that it doesn’t automatically call it on startup. Only after I tilt my screen. Also, if I add that to the constructor of Main, it still shows the right value.

RESIZE is dispatched immediately after your main class’s constructor. This is how it goes:

  1. Your constructor
  2. ADDED_TO_STAGE event
  3. FULL_SCREEN event (if in fullscreen)
  4. RESIZE event

There’s nothing else in between, and the RESIZE event is always dispatched (except in Flash).

So if the event always happens, why aren’t you seeing it?

Try putting a trace statement before stage.addEventListener(), to make sure the listener is being added when you think it is.

haxelib upgrade fixed it. Weird. I only started coding in haxe on this computer a few weeks ago, so I was unlucky enough to start when there was a bug in the lib apparently. So yeah, resize wasn’t being called until after the upgrade.

I think this was due to an issue where we improved our retina support in Lime, but the OpenFL fix didn’t make it in the matching release for some reason. It should be consistent now :slight_smile:

1 Like