Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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. </p> <p>Depending on the case, you may then need to <strong>draw additional copies</strong> of your image displaced by 3000px in either x, y or both.</p> <p><img src="https://i.stack.imgur.com/dkYwn.jpg" alt="Two of the four cases..."></p> <p>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...</p> <pre><code>// 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 &gt; 3000); boolean yOverflow = (posy+screenHeight &gt; 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 &amp;&amp; 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); } </code></pre> <p>I haven't tested this. You should replace all the <code>3000</code>'s with some variables, such as backgroundWidth and backgroundHeight...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload