In the Corona SDK How to hide a group if the application is paused?

Am I creating a pun and I want to hide the panel when the application is paused?

the code looks great, but it causes strange behavior !!,

when I pause the application, nothing will happen, but when I resume the application, then the panel will disappear!

local onSystem = function( event ) if event.type == "applicationSuspend" then print("suspend") board_group.alpha = 0 end end Runtime:addEventListener( "system", onSystem ) 

Note. You may wonder how can I find out what the application looks like when paused? Answer: Double-click the "Home" button.

Example

SpellTower in good condition

http://cl.ly/image/0A0n0v1A2q0C/o

SpellTower after double-clicking the home button

http://cl.ly/image/2D0p3I3d3T3h/o

you can see how they hide the letters, this is exactly what I want to do for my game, the only difference is that I use the Corona SDK

+4
source share
3 answers

When you make board_group.alpha = 0, you just set the variable, the result will take effect only after updating the screen.

But since the application is paused ... it will not be updated! Thus, changing any graphics to applicationSuspend does not work.

+1
source

I believe the reason is that the application is not considered to be suspended. In normal programming with programming, c means that applicationWillResignActive is called when the user double-clicks the home button. So what you want to do is add this code for this part.

Here is the flow of events: http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/

The Crown seems to have these events:

  • "applicationStart" occurs when the application is launched and all the code in main.lua is executed.

  • "applicationExit" occurs when the user exits the application.

  • "applicationSuspend" occurs when the device needs to pause the application, for example, during a phone call or if the phone goes into sleep mode from inactivity. In a simulator, this corresponds to a simulator running in the background. During the suspension, no events (even enterFrame events) are sent to the application during the suspension, so if you have a code that depends on the time, you must consider the time lost to pause the application.

  • "applicationResume" occurs when the application resumes after suspension. On the phone, this happens if the application is paused due to a phone call. On the simulator, this happens when the simulator was in the background and is now a foreground application.

Therefore, I assume that you should implement it outside of the crown APIs.

In accordance with the coronary documents, you can implement them in the delegate:

You can catch UIApplicationDelegate events through your implementation of the CoronaDelegate protocol.

This protocol complies with the UIApplicationDelegate protocol. The crown internal delegate will call your protocol method, if implemented.

Please note the following:

Methods that Apple has deprecated will be ignored. In most cases, the version of your class will be called after the corresponding Corona version of the UIApplicationDelegate version. There is one situation in which your version will be called earlier. In situations where the application is about to pause or go to the background, your method will be called before the version of Corona, for example. applicationWillResignActive: and applicationDidEnterBackground :.

http://docs.coronalabs.com/native/enterprise/ios/CoronaDelegate.html

But this is just an assumption. Hope this helps!

Edit:

I thought something really simple that you could do is catch it outside and present a pause screen, and then just hide it when the application comes to the fore.

+1
source

So, if you cannot do this (for now), another option is to save the state of the application when the application is about to end, and then set UIApplicationExitsOnSuspend = true in your plist file. This will cause the application to exit instead of pausing, which will allow you to avoid screenshots, effectively "hide" the board, etc. Crash, the application will have to read the state of the session when it starts again ... this is useful if your application can be designed to actually exit without losing your state and, frankly, a little extreme. However, this may be the only way to effectively do what you are trying to do.

Other ideas are to see if you can add a large black layer to the screen even if the application pauses; perhaps this will somehow cause the internal screen to be updated by initially setting setNeedsDisplay. In addition, instead of changing the alpha, you can temporarily delete all your layers and see if this has an effect.

+1
source

Source: https://habr.com/ru/post/1445283/


All Articles