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

  • Home
  • SEARCH
  • 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 8964649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:38:10+00:00 2026-06-15T16:38:10+00:00

I have a problem, that when i hit the Return key, in the state

  • 0

I have a problem, that when i hit the Return key, in the state INTRO (as default) it have to switch to GAME state. It does, but when it does, it blinks between INTRO and GAME State. The Text blinks, and the bar at the bottom blinks.

I’d try to print out the current state, and it seems that its not changing between those two states, but when i run the application, my INTRO state, and GAME state, is both there, and is blinking.

public Renderer() {
    try {
        Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight));
        Display.setTitle(gameTitle);
        Display.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 640, 0, 480, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    lastFrame = getTime();


    while (!Display.isCloseRequested()) {
        //long delta = (long) getDelta();

        System.out.println(state);

        while (Keyboard.next()) {
            if(Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
                if(state == State.INTRO) {
                    clearCanvas();
                    state = State.GAME;
                }
            }
            if(Keyboard.isKeyDown(Keyboard.KEY_BACK)) {
                if(state == State.GAME) {
                    clearCanvas();
                    state = State.INTRO;
                }
            }
        }

        switch (state) {
        case INTRO:
            GL11.glColor3f(1.0f, 1.0f, 1.0f);
            TextDraw.drawString("PRESS 'RETURN' TO START GAME, and then hit CTRL z", Display.getWidth() / 2 - 160, Display.getHeight() / 2);
            TextDraw.drawString("CONTROLS:", Display.getWidth() / 2 - 30, Display.getHeight() / 2 - 50);
            TextDraw.drawString("1 key is Paint Red", Display.getWidth() / 2 - 70, Display.getHeight() / 2 - 70);
            TextDraw.drawString("2 key is Paint Green", Display.getWidth() / 2 - 70, Display.getHeight() / 2 - 85);
            TextDraw.drawString("3 key is Paint Blue", Display.getWidth() / 2 - 70, Display.getHeight() / 2 - 100);
            TextDraw.drawString("CTRL Z is Clear canvas", Display.getWidth() / 2 - 70, Display.getHeight() / 2 - 115);
            TextDraw.drawString("Escape to Close Program", Display.getWidth() / 2 - 70, Display.getHeight() / 2 - 130);
            break;
        case GAME:
            keyBindings();
            int MouseX = Mouse.getX();
            int MouseY = Mouse.getY();
            paint(MouseX, MouseY);
            break;
        }

        Display.update();
        Display.sync(250);
    }

    //Closed
    System.out.println("Program Closed");
    Display.destroy();
    System.exit(0);

}
  • 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-06-15T16:38:11+00:00Added an answer on June 15, 2026 at 4:38 pm

    Try replacing these parts:

    while (Keyboard.next()) {
            if(Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
                if(state == State.INTRO) {
                    clearCanvas();
                    state = State.GAME;
                }
            }
            if(Keyboard.isKeyDown(Keyboard.KEY_BACK)) {
                if(state == State.GAME) {
                    clearCanvas();
                    state = State.INTRO;
                }
            }
        }
    

    with this:

    if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)){
        clearCanvas(); //Don't check for the state which is going to be true most likely, just adds confusion to coding
        state = State.GAME;
    }
    
    if (Keyboard.isKeyDown(Keyboard.KEY_BACK)){
        clearCanvas();
        state = State.INTRO;
    }
    

    If you’re worried about speed if the keys aren’t pressed, don’t worry. The difference is really small, and most likely not noticeable.

    Also, you’re not clearing the screen! Without that, all sorts of remnants can be left on there! Use this method to clear in the main loop:

    while (!Display.isCloseRequested()){
        GL11.glClear(GL_COLOR_BUFFER_BIT);
        //Rest of your code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I have a problem that I illustrated in this question but had no correct
i have a problem that i can't solve ! (sqlite3, but i think it
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that I'm working on for quite some time now. I
I have a problem that has been driving me batty. I have code that
I have a problem that occurs only in a production environment, deployed at heroku.
I have a problem that is getting embarrassingly out of hand. I'm working with
I have this problem that I can ref a button for control it. I
I have a problem that output string must be utf8-formatted, I am writing currently
We have the problem that we have the open project files in our SVN

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.