C++ PauseResume

From J2Play

Jump to: navigation, search

The J2Play wrapper is composed of different tabs, when the player switches between these tabs, or switches to other games, the main PC game has to pause until the player switches back to it. Information about the user’s behaviour with the J2Play wrapper can be obtained by communicating with the wrapper. This section describes how to handle the toolkit's pause and resume events.

Pause and Resume Events

The two events involved with pausing and resuming are:

GamePause - When the user switches to another game or any of the menus

GameResume - When the user switches back.

To receive events from the platform the following code has to be added to your main class:

[event_receiver(native)]
class CAppGameFrameWnd {
public:
  void                      registerHooks(CGDKInstance* inst);
  void                      unregisterHooks(CGDKInstance* inst);
private:
  void      msgPause();
  void      msgResume();
};
void CAppGameFrameWnd::registerHooks(CGDKInstance* inst) 
{
  __hook(&CGDKInstance::GamePause, inst, &CAppGameFrameWnd::msgPause);
  __hook(&CGDKInstance::GameResume, inst, &CAppGameFrameWnd::msgResume);
}
void CAppGameFrameWnd::unregisterHooks(CGDKInstance* inst) 
{
  __unhook(&CGDKInstance::GamePause, inst, &CAppGameFrameWnd::msgPause);
  __unhook(&CGDKInstance::GameResume, inst, &CAppGameFrameWnd::msgResume);
}

Finally, place the code for how your game should behave when the game is paused and resumed by implementing these two functions:

void CAppGameFrameWnd::msgPause() 
{ 
  // Your Code
}
void CAppGameFrameWnd::msgResume() 
{
  // Your Code
}


Links

Personal tools