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

  • Home
  • SEARCH
  • 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 7004779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:14:35+00:00 2026-05-27T21:14:35+00:00

This script draws the map and other stuff: public void render(Canvas canvas) { canvas.drawColor(Color.TRANSPARENT);

  • 0

This script draws the map and other stuff:

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 < mapHeight; row++)
        {

        for (int col = 0; col < 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 < curR & droid.x + decentreX > curL) {
            if (droid.y - decentreY < curD & droid.y + decentreY > 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);
    }

The render(Canvas canvas) methos is called on every frame. How can i scroll the map tiles? I tried this:

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 < mapHeight; row++)
        {

        for (int col = 0; col < 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 & !droid.touched1 & !droid.touched3) {
            curL -= 1;
        }else if (droid.touched1 & !droid.touched & !droid.touched2){
            curU += 1;
        }else if (droid.touched2 & !droid.touched1 & !droid.touched3){
            curL += 1;
        }else if (droid.touched3 & !droid.touched2 & !droid.touched){
            curU -= 1;
        }else if (droid.touched & droid.touched1){
            curL -= 1;
            curU += 1;
        }else if (droid.touched1 & droid.touched2){
            curL += 1;
            curU += 1;
        }else if (droid.touched2 & droid.touched3){
            curL += 1;
            curU -= 1;
        }else if (droid.touched3 & droid.touched){
            curL -= 1;
            curU -= 1;
        }

        curR = curL + tileWidth;
        curD = curU + tileHeight;

        if (droid.x - decentreX < curR & droid.x + decentreX > curL) {
            if (droid.y - decentreY < curD & droid.y + decentreY > 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);
    }

but it didn’t worked. Everything that is not in this method is not important. Help me! 🙂

  • 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-27T21:14:36+00:00Added an answer on May 27, 2026 at 9:14 pm

    Seems that you are changing lcal vars curL and curU. Thore are recalculates from rowBase on each call restricting the movement to the 1-increment you use when checking droid.touched.

    You should change the global position of the tiles by changing the rowBase variables.

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

Sidebar

Related Questions

This script draws the controls, hero, surface and the map: public void render(Canvas canvas)
I have a script that draws an image on a canvas and allows people
This simple Canvas script creates a rectangle with a border and text . It
I'm using this script: var canvas = new fabric.Canvas('game_canvas', { selection: false }); fabric.Image.fromURL('images/bg.jpg',
I wrote a little drawing script (canvas) for this website: http://scri.ch/ When you click
For this script, it checks to see if the file is a microsoft words
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
I'm using this script to display all the images in a folder, but I
Well basically I have this script that takes a long time to execute and
I have this script which basically toggles a bgColor class on and off so

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.