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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:49:33+00:00 2026-05-29T09:49:33+00:00

I am due to start work on a 2D platform game in Java using

  • 0

I am due to start work on a 2D platform game in Java using Java2D, and am trying to devise a way to create a world. I have been reading up about this for the last few hours now, and as far as I can tell, a relatively effective way is to have a text file with a “matrix” of values in it, which is read in by the program in order to create the map (stored in a 2D array).

Now, my plan is to have multiple JComponents that display ImageIcons for the various textures in the world; the JComponent object would depend on the character in the given array index.

  1. Is there anything I may have overlooked?
  2. Will this schematic work with a background image, i.e. when there is a character that represents a blank space, will part of the background be shown?

Apologies if this seems like a lazy question, I can assure you it is not out of laziness. I am merely trying to plan this out before hacking code together.

  • 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-29T09:49:34+00:00Added an answer on May 29, 2026 at 9:49 am

    Unless you have compelling reason to, having a different component for each tile is probably not a good way to go. Look into a Canvas and displaying loaded images at different offsets in it.

    Example:
    480×640 Canvas
    128×16 image file(contains 8 16×16 tile images)
    So your file has a bunch of numbers(characters etc.), we’ll say 0-7 for the 8 tiles in the image. The file has 30×40 numbers, laid out in a grid the same as the canvas. So

    1 2 1 3 4 8 2…
    …

    And to display the code ends up something like(not tested, based on docs)

    Graphics g = //initialize graphics;
    Image yourTileImage = //load your image;
    for (int xpos = 0; xpos < maxX; xpos++)
        for (int ypos = 0; ; ypos < maxY; ypos++)
            int number = //get number from map file
            g.drawImage(Image yourTileImage,
                xpos * 16, ypos * 16, xpos * 16 + 15, ypos * 16 + 15,
                number*16, 0, number+15, 15,
                ImageObserver observer)
    

    Which basically maps the number to your tile image, then puts that tile image into the right spot in the canvas(x,y) coordinates * size of tile.

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

Sidebar

Related Questions

I'm trying to start a service as a user and things work fine, until
i am trying to write a boot loader(hello world sort). i am using Bochs
Lately I have been thinking about developing some basic android app. Its only due
Due to repetitive errors with one of our Java applications: Engine engine_0: Error in
Due to the lack of clientaccesspolicy.xml, there appears to be problems with using Amazon
Due to company constraints out of my control, I have the following scenario: A
Due to lack of capital and time we are having to do our game
Due to a number of constraints that I won't get into, I have to
Due to my future course in Computer Science, I'm now going to start learning
Im trying to work with UISearchDisplay controller the application is launching correctly. When i

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.