In theory the agk command 'GetResumed()' would let you know that you have come back from the background.
However, it only works on Android devices.
I found how (in Tier 2) to catch when the app is going to the background and let you do things like pause it actively (stop things doing stuff).
EDIT: I had to do a fix to make an error go away when executing.
This is the updated template.h file:
#ifndef _H_APP
#define _H_APP
// Link to AGK libraries
#include "agk.h"
// Global values for the app
class app
{
public:
// main vars
unsigned int m_DeviceWidth;
unsigned int m_DeviceHeight;
#ifdef IDE_XCODE
static bool did_start;
#endif
public:
// constructor
app() { memset ( this, 0, sizeof(app)); }
// main app functions
void Begin( void );
void Loop( void );
void End( void );
#ifdef IDE_XCODE
void appGetResumed( void );
#endif
};
extern app App;
#endif
// Allow us to use the LoadImage function name
#ifdef LoadImage
#undef LoadImage
#endif
This is the updated template.cpp file (with a simple message to show that it works):
// Includes, namespace and prototypes
#include "template.h"
using namespace AGK;
app App;
#ifdef IDE_XCODE
// globals
bool app::did_start = false;
#endif
// Begin app, called once at the start
void app::Begin( void )
{
// use device resolution
agk::SetVirtualResolution ( m_DeviceWidth, m_DeviceHeight );
}
// Main loop, called every frame
void app::Loop ( void )
{
#ifdef IDE_XCODE
// indicate started (this needs to be here to avoid an error that might
// make the app get rejected by Apple)
app::did_start = true;
#endif
// say hello
agk::Print ( "Hello iPhone, iPad and iPod!" );
agk::Sync();
}
// Called when the app ends
void app::End ( void )
{
}
#ifdef IDE_XCODE
// Called when the app returns from being in the background
void app::appGetResumed( void )
{
// do anything that needs to be handled after being paused
agk::Message("we are going to back!");
}
#endif
Then, you make this mod in the Core.m file:
- (void)applicationWillResignActive:(UIApplication *)application
{
// added call to let the app know that is going to background
if (app::did_start) App.appGetResumed();
// the regular call to make inactive
[viewController setInactive];
}
I went with the applicationWillResignActive function instead of applicationDidBecomeActive because that one triggers when the app starts up, not just when it had been in the background.
Steve/Paul, might this be some help getting the 'GetResumed()' command to work for iOS?
Cheers,
Ancient Lady
AGK Community Tester