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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:21:58+00:00 2026-05-29T12:21:58+00:00

I have been looking around online to try to find a complete solution but

  • 0

I have been looking around online to try to find a complete solution but as of now, I can only find pieces that don’t fit together.

I’m looking for a program that can look at an image file, loop through the file and isolate the sprites and then save them. After that I need a way to re-access that sprite info so I can display it, but I would like to be able to display the tiles based on my own formulas. Think of a game like advanced wars with little terrain tiles. I want to be able to display those tiles semi-randomly, but within my own parameters.

I would also like to be able to load up a different image file that has the same size sprites as the above image but use these images for animations.

So I have 2 sprite sheets that have a bunch of 64×64 pixel sprites. One of the image files is all my terrain tiles. The other is my unit tiles. I want to be able to read in the sprites and display them any way I please.

I cant for the life of me figure out which way to do this. I’ve looked into Subimaging and drawImage, but I can’t get them to store or redisplay information properly.

Thanks.

EDIT: So ive simplified my question for my own sake and for the sake of everyone else.

Why doesnt the following code work?

package animation;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class AnimTest
{
public static void main(String[] args)
{
    AnimTest test = new AnimTest();
    test.go();
}

public void go()
{
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    MyDrawP drawP = new MyDrawP();
    frame.getContentPane().add(drawP);
    frame.setSize(500,500);
    frame.setVisible(true);
}
    }

   class MyDrawP extends JPanel
    {

public void drawSprite(Graphics g)
{
    try {
        BufferedImage bigImg = ImageIO.read(new File("C:/Users/scott/Desktop/Personal Work/Pixel Art/terrain.png"));

        final int width = 64;
        final int height = 64;

        int x = 0;
        int y = 0;

        bigImg.getSubimage(x, y, width, height);
        g.drawImage(bigImg, 5, 5, this);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
    }

Sorry for the mess, i have NO idea how to format a code block properly.

Now with that code, i want the MyDrawP class to look at my file, grab a 64×64 piece of it starting at 0,0 and then save it and display it in the frame when its added to it. Im pretty sure the problem is that the method drawSprite is never called, but im not sure when to call it and im not sure if anything else is missing.

Again, why doesnt the above code work?

Thanks

  • 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-29T12:21:59+00:00Added an answer on May 29, 2026 at 12:21 pm

    You should override the paintComponent(Graphics) method in your MyDrawP class and call your drawSprite from there.

    Then, the way you “extract” sub-images and draw them on your JPanel should be reworked:

    bigImg.getSubimage(x, y, width, height)
    

    will return a subimage (actually always the one at 0,0 in the code you provide), so you should have something like:

    Image subImage = bigImg.getSubimage(x,y,width,height)
    

    Of course, the next line should use subImage instead of bigImg…

    And you finally have to implement the way you “randomly” choose which subimage you want to draw, and where you want to draw it on your JPanel.

    See http://docs.oracle.com/javase/tutorial/uiswing/painting/step2.html

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

Sidebar

Related Questions

I've been looking around on-line for a solution to this, but I can't seem
I have been looking around the site a bit, but I didn't find any
I have been looking around for an answer to my question but couldn't find
I have been looking around for a solution for this problem that works across
I have been looking around for this but couldn't find an answer anywhere, so
I have been looking around ocn Google and Stackoverflow but haven't found what I
I've been looking around for quite a while and feel that I have a
I've been looking around online, but haven't found very much. As a matter of
I have been looking around for a regex expression that will spit out just
I have been looking around and I find grep and Gawk fairly difficult to

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.