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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:23:54+00:00 2026-05-28T02:23:54+00:00

I am trying to figure out how to make my game draw a certain

  • 0

I am trying to figure out how to make my game draw a certain tile in a specific spot using an image to represent each spot. So if a pixel of that image was the color red a specified picture(tile) would be draw in the game, and each pixel that was green stood for a different specified image. I have seen people who make games do this but I dont know how to do it and I dont know the name for it.

If you need more info I can try to explain what I want to do more. Could someone please help?

  • 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-28T02:23:54+00:00Added an answer on May 28, 2026 at 2:23 am

    That may actually be slower in the long run. I would definitely recommend you use a byte array to represent the tiles, i.e. byte[width][height]. It will be faster, easier to manage and easier to extend to something like spriteData[width][height] if a single byte does not supply enough information anymore.

    However, if you insist on using an image to store game data, you can use something like the following:

    File file = new File("mygamedata.jpg");
    BufferedImage image = ImageIO.read(file);
    
    // Getting pixel color at position x, y (width, height)
    int colour =  image.getRGB(x ,y); 
    int red    = (colour & 0x00ff0000) >> 16;
    int green  = (colour & 0x0000ff00) >> 8;
    int blue   =  colour & 0x000000ff;
    System.out.println("Red colour component = " + red);
    System.out.println("Green colour component = " + green);
    System.out.println("Blue colour component = " + blue); 
    

    Each component will be in the range (0…255) and you can use that to determine the correct tile, i.e.

    Graphics2D gfx = (Graphics2D) offScreenImage.getImage();
    if (red == 120 && green == 0 && blue == 0) {
      gc.drawImage(tile[whichTileYouWantForRed], x, y, null); // where x and y is the pixel you read.
    }
    

    Alternatively, you can skip extracting the components altogether, and simply use colour, i.e.

    if (colour == 0x00ff0000) {
      gc.drawImage(tile[whichTileYouWantForRed], x, y, null); // where x and y is the pixel you read.
    } 
    

    (Which will be slightly faster anyway and actually what you want.)

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

Sidebar

Related Questions

I've been trying to figure out how to make a powder toy style game
I'm trying to figure out how to make a background image scroll slower than
I am trying to figure out how to make my layout have the following
I'm trying to figure out how to make it so that when I'm moving
I'm trying to figure out how to make jQuery slide #content2 down and replace
I'm trying to figure out a way to make demos for a program I've
I've been trying to figure out how I can make a query with MySQL
I'm trying to figure out how if there's a way to make a hostname
I'm trying to figure out how my iOS app should work after Facebook make
I'm trying to make getJSON to use JSONP object, but I can't figure out

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.