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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:48:13+00:00 2026-05-30T18:48:13+00:00

I have an image I’m drawing in java 2d but I want it to

  • 0

I have an image I’m drawing in java 2d but I want it to keep wrapping forever once the coordinates are outside the size of the image. The problem at the moment is that once the coordinates that I specify go outside the size of the image, it draws nothing so the image ends.

E.g an image that constantly moves horizontally and doesn’t end.

int posx = (int) ((Player.x / 20));
int posy = (int) ((Player.y / 20));
g.drawImage(SpaceBGLayer0, 0, 0, screenwidth, screenheight, posx, posy, posx+3000, posy+3000, null, null);
  • 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-30T18:48:14+00:00Added an answer on May 30, 2026 at 6:48 pm

    To wrap the image, you need to first test whether there’s any ‘overflow’ (ie any parts of the screen where wrapping is required). There are 4 cases: no overflow, x-overflow, y-overflow, x- and y-overflow.

    Depending on the case, you may then need to draw additional copies of your image displaced by 3000px in either x, y or both.

    Two of the four cases...

    I’ve assumed that your (posx,posy) point corresponds to the lower left corner of the screen, and that both screenWidth and screenHeight are less than 3000…

    // calculate posx and posy, ensuring they lie within 0-2999:
    int posx = (3000+((int)(Player.x / 20))%3000)%3000;
    int posy = (3000+((int)(Player.y / 20))%3000)%3000;
    
    // test for overflow:
    boolean xOverflow = (posx+screenWidth > 3000);
    boolean yOverflow = (posy+screenHeight > 3000);
    
    // draw the image:
    drawMyImage(posx,posy);
    // if necessary, draw displaced copies:
    if(xOverflow) drawMyImage(posx-3000,posy);
    if(yOverflow) drawMyImage(posx,posy-3000);
    if(xOverflow && yOverflow) drawMyImage(posx-3000,posy-3000);
    
    ...
    
    private static void drawMyImage(int x, int y){
        int dx1 = Math.max(-x,0);
        int dy1 = Math.max(-y,0);
        int dx2 = Math.min(3000-x,screenWidth);
        int dy2 = Math.min(3000-y,screenHeight);
        int sx1 = Math.max(x,0);
        int sy1 = Math.max(y,0);
        int sx2 = Math.min(x+screenWidth,3000);
        int sy2 = Math.min(y+screenHeight,3000);
        g.drawImage(SpaceBGLayer0, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null, null);
    }
    

    I haven’t tested this. You should replace all the 3000‘s with some variables, such as backgroundWidth and backgroundHeight…

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

Sidebar

Related Questions

I have image data and i want to get a sub image of that
I have: image 1:Many imageToTag Many:1 tag I want to issue a query that
I have image and txt file of same size say 200 KB. Now i
So I have Image like this (source: de-viz.ru ) I want to get something
So I have Image like this (source: de-viz.ru ) I want to get something
I have a problem... In my view i have Image.If i click on image
I have an image and on it are logos (it's a map), I want
I have image with some object at not solid background. I want to extract
I have image which size was 600 * 600 and it was displayed on
I want to have image button for browse and upload I have textbox using

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.