Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:40:49+00:00 2026-05-25T18:40:49+00:00

I’m trying to create a game loop using this tutorial . I have tried

  • 0

I’m trying to create a game loop using this tutorial.

I have tried to implement this in the initial activity class as shown below but I have run into a few problems. I have requested the fullcreen and no title features as shown but I don’t get them and the requestRender does not work.

When “running” is set to false then the game loop is skipped and the renderer renders one frame (rendermode set to dirty)

This is not something that it does when running= true.

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;



public class Practice extends Activity {

private Input input;
private GLSurfaceRenderer glSurfaceRenderer;
private final static int maxFPS = 30;
private final static int maxFrameSkips = 5;
private final static int framePeriod = 1000 / maxFPS;
public final static String TAG = "input";

public boolean running = true;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    input = new Input(this);
    setContentView(input);

    long beginTime;
    long timeDiff;
    int sleepTime;
    int framesSkipped;

    sleepTime = 0;
    while (running) {
        Log.d(TAG, "gameRunning");
        beginTime = System.currentTimeMillis();
        framesSkipped = 0;
        this.input.update();
        this.input.requestRender();
        timeDiff = System.currentTimeMillis() - beginTime;
        sleepTime = (int)(framePeriod - timeDiff);

        if (sleepTime > 0) {
            try{
                Thread.sleep(sleepTime);
            }catch(InterruptedException e){}
        }

        while(sleepTime < 0 && framesSkipped < maxFrameSkips){
            this.input.update();
            sleepTime += framePeriod;
            framesSkipped++;
            Log.d(TAG, "Frames Skipped");
        }

    }
}
}

At the moment the game logic is updating fine but the renderer is not rendering at all (just a black screen)

I’m pretty sure this is just a simple re-shuffling of code but does anybody have any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:40:50+00:00Added an answer on May 25, 2026 at 6:40 pm

    The root cause of your problem is not letting onCreate() return. This is required in order for the app to operate, this is the thread that handles all UI input and changes. I see a lot of energy here that’s unfocused check out the tutorials, basic UI tutorials, read about the Android Lifecycle and watch out for ANR’s. They will give you a better understanding about how things work and how to combine your activity with a second thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.