display.captureScreen for dissolve transitions?

Hello fellow Appthusiasts,

I’m hoping to save some texture memory usage by using display.captureScreen to transition from one scene to the next. I’m aware of previous attempts by the community (Director class), and even most recently by Corona themselves with Storyboard to help developers be able to handle loading and unloading and generally smooth transitioning between scenes.

My problem is that the scene the user is viewing, prior to the transition, I’m using up almost all the available texture memory (yes, you can go over 24 MB of texture memory, but I’ve noticed that in many cases, when you do, the device crashes, so this isn’t an option). So in all current implementations of scene switching, even with the Storyboard or Director solutions (even with my own custom written code), in order to smoothly transition to the next scene and do something like a dissolve, the NEXT scene needs to be preloaded, and the current scene must remain on screen. Since I’m already using up all my available texture memory, I cannot preload the next scene without going beyond the limit.

SO! My thought was, would it be possible to use display.captureScreen to take a screenshot and use that as my visual placeholder for a dissolve transition. So my code would look something like this:

  1. Scene loads & plays (texture mem: 20 mb)
  2. Scene ends, take screenshot via display.captureScreen and bring this screenshot to the front of my display (texture mem: 24 mb - assuming 4 mb for 1024 x 768 image on iPad)
  3. Unload my current scene (texture mem: 4 mb)
  4. Load the upcoming scene, positioning characters behind the screenshot (texture mem: 24 mb)
  5. Change the alpha of the screenshot overtime, dissolving the last scene into the next one (texture mem: 20 mb)
  6. celebrate the cinematic awesomeness!!!

This seems like a sound plan, BUT for the life of me, I can’t get display.captureScreen to function as it seems to me that it should. Calling the function display.captureScreen( true ), I get the handle of the cap back, but nothing comes up on my screen as in the example. I can see the saved file on my file system, so the function is kiiiiiiinda working, except when I view the file, it’s all black!! So it didn’t cap the screen, but it tried to… it is however the correct resolution 1024 x 768 (I’m on Windows, btw… haven’t tested this on Mac yet).

In the example, the user is rendering rects and circles and capturing that. I am using sprites and background images. Is there a difference?

Thanks in advance for the help!

Regards,
Scott D Brooks
Little Halo Games [import]uid: 63276 topic_id: 21982 reply_id: 321982[/import]

*bump* [import]uid: 63276 topic_id: 21982 reply_id: 87462[/import]

Its a bug. I’ve opened a couple of cases about it.

display.save will work on device, and also on the simulator, but has some issues with certain graphics cards on simulator. Test the ‘screen capture’ example on your computer to see if it works for you.

display.captureScreen just doesn’t work for me at all. On device or on simulator :confused:

I’d suggest you just use display.save - saving to the temp folder, then reload the image back. The temp folder gets nuked when your app quits anyway. You can come back and change it to captureScreen later once they fix the bug. [import]uid: 8872 topic_id: 21982 reply_id: 87472[/import]

Hey Kam, thanks for getting back to me. I had tested the sample in the docs and confirmed that I saw only black screens.

Wondering if the issue was related to my version, decided to update Corona simulator to today’s daily build and VIOLA! It works!

Now I’ve got super slick transitions!

Enjoy! [import]uid: 63276 topic_id: 21982 reply_id: 87478[/import]

Looks like they fixed it in the build before last!

•casenum 10638,11643: Mac: Another workaround attempt to solve OpenGL corruption display problems when crossing multiple video cards/displays. This affects all OpenGL rendering on the Mac. Please test and report any rendering problems introduced by this change.

The black screen was due to openGL FBO errors (which you probably saw in the console), as it uses a framebuffer capture to grab the screen. So previously neither captureScreen nor .save would even capture anything on the sim if you had this problem.

That said, on device .save did work, but captureScreen never did for me. That looks like a totally different problem. Have you tested on device to see if it works? Would be great if they’ve fixed that too now!
[import]uid: 8872 topic_id: 21982 reply_id: 87479[/import]

hmmmm, I’ll test it out tomorrow and report back. Need sleepy. [import]uid: 63276 topic_id: 21982 reply_id: 87481[/import]

Hey kam187,

It seems that captureScreen does indeed work on the device (using iPad for testing). It appears that the scaling of the screen capture is off though. I’m looking into what’s causing it. Its a slow process having to build, test, change code & rebuild… Will report back when I find out what’s going on.

Seems like it may be related to my build/config resolution settings. Atm, the screenshot shows, but its center is in the tip right corner of the screen and appears to be scrunched vertically.

Scott D Brooks
[import]uid: 63276 topic_id: 21982 reply_id: 88340[/import]

For anyone else interested in this thread, I’ll post my final understanding of how display.captureScreen() is working on the device today.

After some more self-contained tests, I found that the sample code in the API docs *does not* work, meaning that I was unable to see the screenshot image of the box and circle, as expected. In fact, it was purely black.

But, in my usage within my game, I was able to see screen capture of sprite loaded images being displayed on the screen. The odd part was that in the simulator, the screenshots were, by default, centered and scaled properly. But on the device, the center of the screen shot image moved to the top right corner after capture and was scaled incorrectly. My intuition was that this was related to my configuration settings in config.lua or build.settings… but since I was on a deadline to release our beta, I was unable to pin down the exact cause. I did however fumble through and manage to figure out how the image needed to be scaled in order for it to display properly:

[lua] utils.screens[name] = display.captureScreen()
utils.screens[name].x = display.contentWidth / 2
utils.screens[name].y = display.contentHeight / 2
utils.screens[name]:scale(.749,1.333)[/lua]

Hope that helps someone out there! Once I nail down the exact cause of the scaling problem, I’ll post here once more.

Regards,
Scott D Brooks
[import]uid: 63276 topic_id: 21982 reply_id: 88827[/import]