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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:31:43+00:00 2026-06-08T09:31:43+00:00

Could you please help with the endless background for the level? I’m currently writing

  • 0

Could you please help with the endless background for the level?

I’m currently writing a primitive game using slick2d, the gameplay is similar to Mario.

I have two pictures – img1 and img2 (both 1280×480, while the screen resolution is 640×480).
Initially the X of the img2 is == (X of img1 + width of img1). I.e. its glued to the end of the img1.
When the img1 is out of the left screen border, it’s X coordinate becomes img2X + imgWidth.

The logic looks right for me, but sometimes the pictures getting overstriked (a lot, approx 1/4 of the screen).
Is there any mistakes in the logic? Does the approach is good? Maybe there is more simple and right way to do so?

The pseudo-code look like below:

class BkgDrawer {


Image img1 = new Image("imgs/background/bkg1.png");
Image img2 = new Image("imgs/background/bkg2.png");

int img1Width = img1.getWidth(); //1280
int img2Width = img2.getWidth(); //1280
int screenResolution = game.getResolution; //640

Vector2f position1 = new Vector2f (0,0);
Vector2f position2 = new Vector2f (position1.x+img1.getWidth(), 0); //initially position2 is glued to the end of img1

public void render(    ) {
  if (position1.x + img1Width < 0) { //the img is over the left border of the screen
      position1.x = position2.x + img2Width; //glue it to the end of  img2
  }
//the same for the img2
  if (position2.x + img2Width < 0) { //the img is over the left border of the screen
      position2.x = position1.x + img2Width; //glue it to the end of  img2
  }
  img1.draw(position1.x, position1.y);
  img2.draw(position2.x, position2.y);
  //move coordinate to get the background moving.
  position1.x -= MOVING_STEP;
  position2.x -= MOVING_STEP;
  }
}

Sorry for the lot of text and thanks

  • 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-08T09:31:45+00:00Added an answer on June 8, 2026 at 9:31 am

    I have found only one bug and it will only have an affect if the two images have different widths: Your two if-statements use the same width img2Width

    You may have noticed that you have duplicate code to handle the rendering and repositioning of each background. Might I suggest that you refactor the background code into a Background class that contains the background image, position, and and update method that repositions it by MOVING_STEP. You will avoid mistakes like the one I mentioned above.

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

Sidebar

Related Questions

I wonder if anyone could please help me I have been using HTML tidy
Could you please help me out to find the correct deceleration rate for the
Could you please help me converting this c++ code into python: I am trying
Could someone please help me to convert this String into a Map ... String
Could you please help me to get image upload working on a view with
Could you please help me how to format a struct timeval instance to human
Could someone please help me in here, I'm just a beginner who want to
Could you please help me find out the time complexity of the Fleury' algorithm
Could somebody please help me get Clang up and running? (I don't have 3.2)
Could someone please help explain why I can't get this to work? I properly

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.