Note that there are some explanatory texts on larger screens.

plurals
  1. POContinuously scroll one large seamless image in any direction
    primarykey
    data
    text
    <p>The issue is gaming related, but I think it could be applied to other use cases.</p> <p>I have a seamless image larger than the screen. About twice as big. The goal is to have this image scrollable in any direction on a surface. This is for Android.</p> <p>I've seen a few questions/answers regarding images in general, but not seamless images. </p> <p>The difference here, and the question I have is how to handle scrolling when at some points, there can be 4 separate pieces of the image on display (when the user scrolls halfway through the image diagonally).</p> <p>It's pretty obvious how to do it when you want to scroll an image edge to edge. Use a world value, and use a rectangle to display a sort of 'viewport' of where you are.</p> <p>Something like:</p> <pre><code>Rect oRect1 = new Rect(dWorldX, dWorldY, dWorldX + canvas.getWidth(), dWorldY + canvas.getHeight()); Rect oRect2 = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); canvas.drawBitmap(largeBitmapTexture, oRect1, oRect2, new Paint()); </code></pre> <p>But when the bitmap is seamless and continuously scrolling, this presents a programming challenge for me. Do I use a bunch of if statements? Is there a more efficient way of doing something like this? </p> <p>edit: A few more thoughts. One complication here is that the world (x,y) is infinitely large. Because of this, I have to use divisions of the screen width and height to display what needs to be displayed. I was originally considering just having 4 iterations of Rect since there would never be more than 4 pieces of the image on the screen. If that makes any sense. I guess I'm just a little fuzzy about how to calculate.</p> <p>edit: Here is the code I have now, with suggestions from @glowcoder. </p> <pre><code>public void draw(Canvas canvas){ int iImagesOverX=0; int iImagesOverY=0; iImagesOverX = (int)dX / mCloud.getIntrinsicWidth(); iImagesOverY = (int)dY / mCloud.getIntrinsicHeight(); mCloud.setBounds(iImagesOverX * (int)mCloud.getIntrinsicWidth() , iImagesOverY * (int)mCloud.getIntrinsicHeight() , (iImagesOverX * (int)mCloud.getIntrinsicWidth()) + mCloud.getIntrinsicWidth() , (iImagesOverY * (int)mCloud.getIntrinsicHeight()) + mCloud.getIntrinsicHeight() ); Log.d(TAG, "bounds:"+ mCloud.getBounds()); mCloud.draw(canvas); mCloud.setBounds((iImagesOverX + 1) * (int)mCloud.getIntrinsicWidth() , iImagesOverY * (int)mCloud.getIntrinsicHeight() , ((iImagesOverX + 1) * (int)mCloud.getIntrinsicWidth()) + mCloud.getIntrinsicWidth() , (iImagesOverY * (int)mCloud.getIntrinsicHeight()) + mCloud.getIntrinsicHeight() ); mCloud.draw(canvas); mCloud.setBounds((iImagesOverX + 1) * (int)mCloud.getIntrinsicWidth() , (iImagesOverY + 1)* (int)mCloud.getIntrinsicHeight() , ((iImagesOverX + 1) * (int)mCloud.getIntrinsicWidth()) + mCloud.getIntrinsicWidth() , ((iImagesOverY + 1) * (int)mCloud.getIntrinsicHeight()) + mCloud.getIntrinsicHeight() ); mCloud.draw(canvas); mCloud.setBounds((iImagesOverX) * (int)mCloud.getIntrinsicWidth() , (iImagesOverY + 1)* (int)mCloud.getIntrinsicHeight() , ((iImagesOverX) * (int)mCloud.getIntrinsicWidth()) + mCloud.getIntrinsicWidth() , ((iImagesOverY + 1) * (int)mCloud.getIntrinsicHeight()) + mCloud.getIntrinsicHeight() ); mCloud.draw(canvas); Log.d(TAG, "imagesoverx:"+ iImagesOverX); } </code></pre> <p>I had to add dX and dY to the bounds to get the images to move. However, once you go one 'tile' over to the right, the third tile does not appear.</p> <p>So this is partly working, but not quite where I need to be. There are 4 panels, but only because of the 4 instances of bounds and draw. I need these 4 panels to draw where they need to be no matter where we are with x and y.</p>
    singulars
    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.
 

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