Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
The Android Game Developer???s Handbook

You're reading from  The Android Game Developer???s Handbook

Product type Book
Published in Aug 2016
Publisher Packt
ISBN-13 9781785885860
Pages 368 pages
Edition 1st Edition
Languages
Author (1):
Avisekhar Roy Avisekhar Roy
Profile icon Avisekhar Roy

Table of Contents (20) Chapters

The Android Game Developer's Handbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Android Game Development 2. Introduction to Different Android Platforms 3. Different Android Development Tools 4. Android Development Style and Standards in the Industry 5. Understanding the Game Loop and Frame Rate 6. Improving Performance of 2D/3D Games 7. Working with Shaders 8. Performance and Memory Optimization 9. Testing Code and Debugging 10. Scope for Android in VR Games 11. Android Game Development Using C++ and OpenGL 12. Polishing Android Games 13. Third-Party Integration, Monetization, and Services Index

Interrupt handling


The game loop is a continuous process. Whenever an interrupt occurs, it is necessary to pause every running thread and save the current state of the game to ensure that it resumes properly.

In Android, any interrupt triggers from onPause():

@Override
protected void onPause() 
{
  super.onPause();
  // pause and save game loop here
}
// When control is given back to application, then onResume() is // called.
@Override
protected void onResume() 
{
  super.onResume();
  //resume the game loop here
}

Now, we need to change the class where the actual game loop is running.

First, declare a Boolean to indicate whether the game is paused or not. Then, put a check in the game loop. After that, create a static method to deal with this variable:

private static boolean gamePaused = false;
@Override
public void onDraw(Canvas canvas)
{
  if(gameRunning && ! gamePaused)
  {
    MainGameUpdate();
    RenderFrame(canvas);
    
    invalidate();
  }
  else if(! gamePaused)
  {
    /...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}