iOS multitasking switcher system image vs application image discrepancy workaround
Asked Answered
M

1

8

It seems to me that the system takes a different screen capture that the one my app takes on applicationWillResignActive.

To my surprise there is a delay of about 0.6 secs between the image taken by the system (b) and the image taken by the game (d). It kind of makes sence if the system needs to take the screen capture before applicationWillResignActive, but for a game with fast moving objects this can be easily noticed by the player.

How can I workaround this?

The following are the steps the player makes and how it causes such discrepancy:

enter image description here

(a) The player pulses the home button when she is playing. (b) The system screen capture is taken. (c) The player taps the game icon. (d) The game is launched with the screen capture taken on applicationWillResignActive. (e) The game is paused showing the discrepancy in a fast moving object.

Mureil answered 8/7, 2014 at 15:12 Comment(6)
When did you pause your game? You can put a breakpoint on _saveSnapshotWithName: and see when it is called.Conditioned
@LeoNatan The game is paused on applicationWillResignActive although the screenshot is taken in applicationDidEnterBackground, I've tested taking the screenshot on applicationWillResignActive but the result is the sameMureil
If the game is paused in applicationWillResignActive, then the screenshot taken in applicationDidEnterBackground should be accurate. Perhaps your problem is when returning.Conditioned
@LeoNatan I think that the system takes a screenshot for the zoom out effect when the user pulses the home button, but the app continues running for about 0.6 secs before applicationWillResignActive is called. Please see this video, the home button is pulsed at 4:00, but the screenshot taken by the app is at 4:55, i.e. ~0,6 secs later.Mureil
Could be, but the timer app does not pause, so when taking a screenshot, it has advanced. If you pause, and the it takes some time take a screenshot, it shouldn't matter. If it takes some time before the app is paused, this is a problem. Add log output to your app and see how long between pressing the home button and the app resigning active. Do this on a real device, as the simulator is buggy.Conditioned
@Mureil why not use youtube, your video hosting site is kind of creepy.Schaffhausen
S
0

I believe this is because your game rendering is not on main thread(certainly it shouldn't be on main thread), so when applicationDidEnterBackground/applicationWillResignActive is returned, the system takes a screen shot from video card's buffer immediately.

At this time, your game loop thread is still running, so it may update some frames before it is paused.

I don't know how you implement your game loop, but you can try this:

In applicationDidEnterBackground/applicationWillResignActive, put a global semaphore(dispatch_semaphore_t) and block the main thread, in your game loop, observe the semaphore and if it exist, pause your game loop, then signal the semaphore.

This will assure that the screen shot is taken after your game is paused.

Also notice that after applicationWillResignActive, the system will take the snapshot for task switcher, and after applicationDidEnterBackground, the system will take snapshot for next time you app enter foreground.

Hope this will help you.

Schaffhausen answered 14/1, 2015 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.