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 9200957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:53:20+00:00 2026-06-17T22:53:20+00:00

The problem I’m having is with my render loop. My application is a series

  • 0

The problem I’m having is with my render loop. My application is a series of ‘Tile’ objects each with an x and y coordinate and image. When the program starts it creates a 10×10 grid of these tiles on screen. However, not all the squares can be seen at the same time, so you can use the arrow keys to pan around them. When the key is pressed it uses a for loop to cycle through all the currently rendered tile (stored in an ArrayList) and shifts them all 16 in the appropriate direction. The problem is some of the tiles flicker. I can see when scrolling that one half of the screen doesn’t move in time to be rendered in the right spot, making a black gap between that and the other half of the tiles. how do I ensure that all tiles are moved before rendering?

render function from my Core class

public static void render()
{
    while(true)
    {
        Graphics g = buffer.getDrawGraphics();
        try
        {
            g.setColor(Color.black);
            g.fillRect(0, 0, 1280, 720);
            if(renderQueue != null)
            {
                for(int i = 0; i<renderQueue.size(); i++)
                {
                    Tile t = renderQueue.get(i);
                    g.drawImage(t.getImage(), t.getX(), t.getY(), null);
                }
            }
            if(!buffer.contentsLost())
            {
                buffer.show();
            }
        }
        finally
        {
            if(g != null)
            {
                g.dispose();
            }
        }
    }
}

And here’s the movement update function from the Input class

public void keyPressed(KeyEvent ke)
{
    int e = ke.getKeyCode();
    switch(e)
    {
        case 38://up
            if(scrollY > 0)
            {
                scrollY -= 16;
                for(int i = 0; i<Core.renderQueue.size(); i++)
                {
                    Core.renderQueue.get(i).incrementY(16);
                }
            }
            break;
        case 40://down
            if(scrollY < 560)
            {
                scrollY += 16;
                for(int i = 0; i<Core.renderQueue.size(); i++)
                {
                    Core.renderQueue.get(i).incrementY(-16);
                }
            }
            break;
        case 37://right
            if(scrollX < 0)
            {
                scrollX += 16;
                for(int i = 0; i<Core.renderQueue.size(); i++)
                {
                    Core.renderQueue.get(i).incrementX(16);
                }
            }
            break;
        case 39://left
            if(scrollX > 0)
            {
                scrollX -= 16;
                for(int i = 0; i<Core.renderQueue.size(); i++)
                {
                    Core.renderQueue.get(i).incrementX(-16);
                }
            }
            break;
    }

Thanks in advance!

  • 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-17T22:53:21+00:00Added an answer on June 17, 2026 at 10:53 pm

    It sounds like the tiles are being rendered while the coordinates for some of the tiles still have to be changed by Input.keyPressed. You could fix that by directly using scrollX and scrollY to draw the tile images in Core.render, instead of changing the coordinates for each of the tiles. If you copy the scroll values to two local variables at the begin of the while loop in render, the same values will be used for each tile.

    Another option is to create a new list with tiles that have the modified coordinates (you could use the images from the current list). When the new list is complete, you could set a flag like newRenderQueue which will be picked up in render. When a new iteration of the while loop in render starts, you can replace the render queue with the new list and reset the flag.

    P.S. Welcome to Stack Overflow! As Andrew Thompson already mentioned, it’s very helpful to provide a complete example of your problem. This way people can quickly investigate the issue and provide (hopefully useful) advice… 😉

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

Sidebar

Related Questions

Problem: I've written State Machine for my android application. It is separate class, extension
Problem occurs when I try to reuse views in ListView having several custom layouts.
Problem description is follows: There are n events for particular day d having start
Problem Description I am writing Android application and I need to add to my
Problem: I have a monitor program in Python that uses subprocess' Popen to start
Problem: How do I loop through a list, look at the first char in
PROBLEM: Need query to return the MONTH and YIELD for Each Year. For some
PROBLEM: When I'm working with a Scala Play 2.0.4 application from within IntelliJ IDEA
Problem in short: How do I display a dynamic image on a template, when
Problem: I have 3 machines, each machine have a limit of 30 ms time,

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.