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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:16:54+00:00 2026-06-14T03:16:54+00:00

I have a little problem, when I try to draw multiple layers of tiles

  • 0

I have a little problem, when I try to draw multiple layers of tiles in my game, only the top layer shows up. For example, I have a for loop to draw air tiles, and below that I have another to draw stone tiles. Only the air tiles will draw, the stone tiles won’t no matter what I do. Heres my map class:

public class Map {

public static final int CLEAR = 0;
public static final int STONE = 1;
public static final int GRASS = 2;
public static final int DIRT = 3;

public static final int WIDTH = 32;
public static final int HEIGHT = 24;

public static final int TILE_SIZE = 25;

static ArrayList<ArrayList<Integer>> map = new ArrayList<ArrayList<Integer>>(WIDTH * HEIGHT);

Image air, grass, stone, dirt;

public Map() {

    for (int x = 0; x < WIDTH; x++) {
        ArrayList<Integer> yaxis = new ArrayList<Integer>();
        for (int y = 0; y < HEIGHT; y++) {
            yaxis.add(CLEAR);
        }
        map.add(yaxis);
    }

    for (int x = 0; x < WIDTH; x++) {
        ArrayList<Integer> yaxis = new ArrayList<Integer>();
        for (int y = 0; y < HEIGHT; y++) {
            yaxis.add(STONE);
        }
        map.add(yaxis);
    }

    try {
        init(null, null);
    } catch (SlickException e) {
        e.printStackTrace();
    }
    render(null, null, null);

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    air = new Image("res/air.png");
    grass = new Image("res/grass.png");
    stone = new Image("res/stone.png");
    dirt = new Image("res/dirt.png");
}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) {

    for (int x = 0; x < map.size(); x++) {
        for (int y = 0; y < map.get(x).size(); y++) {
            switch (map.get(x).get(y)) {
            case CLEAR:
                air.draw(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
                break;
            case STONE:
                stone.draw(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
                break;
            case GRASS:
                grass.draw(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
                break;
            case DIRT:
                dirt.draw(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
                break;
            }
        }
    }
}

}

If anyone could help, that would be amazing!

  • 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-06-14T03:16:56+00:00Added an answer on June 14, 2026 at 3:16 am

    You’re adding air rows then adding stone rows here:

    for (int x = 0; x < WIDTH; x++) {
        ArrayList<Integer> yaxis = new ArrayList<Integer>();
        for (int y = 0; y < HEIGHT; y++) {
            yaxis.add(CLEAR);
        }
        map.add(yaxis);
    }
    
    for (int x = 0; x < WIDTH; x++) {
        ArrayList<Integer> yaxis = new ArrayList<Integer>();
        for (int y = 0; y < HEIGHT; y++) {
            yaxis.add(STONE);
        }
        map.add(yaxis);
    }
    

    The problem is that the stone tiles are out of the expected map size (32 x 24) because you’ve addded twice a much rows as you think you would.

    Try replacing the list of lists by an array and you will see that you’re going out of bounds.

    Edit: here’s a proper way to initialize your map with random data:

    java.util.Random random = new java.util.Random();
    
    for (int x = 0; x < WIDTH; x++) {
        ArrayList<Integer> yaxis = new ArrayList<Integer>();
        map.add(yaxis);
        for (int y = 0; y < HEIGHT; y++) {
            yaxis.add(random.nextInt(4));
        }
    }
    

    Note that afterwards you won’t be adding tiles, just changing the values, eg.

    map.get(10).set(5, CLEAR);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with jQuery. I try to show multiple texts in
I have created a little test project to try to resolve a problem I
I've finished my C# application, but I have a little problem: When I try
I have a little problem. I try to replace a string(well a line) by
I have a little problem. I try to add an element in XML with
I have a little problem with my script. When I try to run it
I have a little problem with elFinder. I'll try to explain the best I
I have a little problem when I try to run my Android application. The
I have a little problem that perhaps you can help me with. I try
I try to validate my xhtml and i have a little problem with this:

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.