Note that there are some explanatory texts on larger screens.

plurals
  1. POTile based map scrolling
    primarykey
    data
    text
    <p>This script draws the map and other stuff:</p> <pre><code>public void render(Canvas canvas) { canvas.drawColor(Color.TRANSPARENT); Drawable myImage; int tileWidth = 50; int tileHeight = 50; int mapWidth = 3; int mapHeight = 3; int rowBaseX = 0; int rowBaseY = 0; int[][] board = new int[][] { {0,0,0}, {0,0,0}, {0,0,2} }; for (int row = 0; row &lt; mapHeight; row++) { for (int col = 0; col &lt; mapWidth; col++) { Resources res = this.getContext().getResources(); switch(board[row][col]) { case 0: myImage = res.getDrawable(R.drawable.tile1); break; case 1: myImage = res.getDrawable(R.drawable.tile2); break; default: myImage = res.getDrawable(R.drawable.tile3); break; } int curL; int curU; int curR; int curD; curL = rowBaseX + (col * tileWidth); curU = rowBaseY + (row * tileHeight); curR = curL + tileWidth; curD = curU + tileHeight; if (droid.x - decentreX &lt; curR &amp; droid.x + decentreX &gt; curL) { if (droid.y - decentreY &lt; curD &amp; droid.y + decentreY &gt; curU) { myImage.setBounds(curL,curU,curR,curD); myImage.draw(canvas); } } } } droid.draw(canvas); butt.draw(canvas); butt1.draw(canvas); butt2.draw(canvas); butt3.draw(canvas); buttz.draw(canvas); buttz1.draw(canvas); buttz2.draw(canvas); buttz3.draw(canvas); buttx.draw(canvas); } </code></pre> <p>The render(Canvas canvas) methos is called on every frame. How can i scroll the map tiles? I tried this:</p> <pre><code>public void render(Canvas canvas) { canvas.drawColor(Color.TRANSPARENT); Drawable myImage; int tileWidth = 50; int tileHeight = 50; int mapWidth = 3; int mapHeight = 3; int rowBaseX = 0; int rowBaseY = 0; int[][] board = new int[][] { {0,0,0}, {0,0,0}, {0,0,2} }; for (int row = 0; row &lt; mapHeight; row++) { for (int col = 0; col &lt; mapWidth; col++) { Resources res = this.getContext().getResources(); switch(board[row][col]) { case 0: myImage = res.getDrawable(R.drawable.tile1); break; case 1: myImage = res.getDrawable(R.drawable.tile2); break; default: myImage = res.getDrawable(R.drawable.tile3); break; } int curL; int curU; int curR; int curD; curL = rowBaseX + (col * tileWidth); curU = rowBaseY + (row * tileHeight); if (droid.touched &amp; !droid.touched1 &amp; !droid.touched3) { curL -= 1; }else if (droid.touched1 &amp; !droid.touched &amp; !droid.touched2){ curU += 1; }else if (droid.touched2 &amp; !droid.touched1 &amp; !droid.touched3){ curL += 1; }else if (droid.touched3 &amp; !droid.touched2 &amp; !droid.touched){ curU -= 1; }else if (droid.touched &amp; droid.touched1){ curL -= 1; curU += 1; }else if (droid.touched1 &amp; droid.touched2){ curL += 1; curU += 1; }else if (droid.touched2 &amp; droid.touched3){ curL += 1; curU -= 1; }else if (droid.touched3 &amp; droid.touched){ curL -= 1; curU -= 1; } curR = curL + tileWidth; curD = curU + tileHeight; if (droid.x - decentreX &lt; curR &amp; droid.x + decentreX &gt; curL) { if (droid.y - decentreY &lt; curD &amp; droid.y + decentreY &gt; curU) { myImage.setBounds(curL,curU,curR,curD); myImage.draw(canvas); } } } } droid.draw(canvas); butt.draw(canvas); butt1.draw(canvas); butt2.draw(canvas); butt3.draw(canvas); buttz.draw(canvas); buttz1.draw(canvas); buttz2.draw(canvas); buttz3.draw(canvas); buttx.draw(canvas); } </code></pre> <p>but it didn't worked. Everything that is not in this method is not important. Help me! :)</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