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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:07:30+00:00 2026-06-01T12:07:30+00:00

So I am writing a game in Java, and I started out using the

  • 0

So I am writing a game in Java, and I started out using the drawRect() method to represent players, enemies, and shots. Everything was great.
Then I decided to try to get fancy.
I found myself creating .png images of each object and used the Graphics2D drawImage() method. Everything began to slow down. Is there any alternative way to speed up the process?

My animation is based on a Swing Timer

    public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2d = (Graphics2D)g;
    player1.paintShips(g);
    g2d.drawImage(bGround, 14, 14, this);
    try{
        for(Shot s: liveRounds){ //liveRounds is an ArrayList of Shots
            if(!inBounds.contains(s.getRect()) || villains.collision(s)){
                if(villains.collision(s)){
                    villains.collided(s, this);
                }
                liveRounds.remove(s);
                roundCount--;
            }
            else{
                s.paintShot(g, this);                   
            }
        }
    }catch(ConcurrentModificationException e){};
    villains.paintEnemyGrid(g, this);
    g2d.setColor(Color.cyan);
    g2d.draw(hitZone1);
    g2d.setColor(Color.red);
    g.drawString("X: " + player1.getX(1) + "  Y: " + player1.getY(1), 370, 150);
    g2d.draw(inBounds);
    g.drawString(score + "", 440, 40);
    g.dispose();
} 

Any tips or tutorials on animation?
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-06-01T12:07:32+00:00Added an answer on June 1, 2026 at 12:07 pm

    A 10 ms delay is 100 frames per second. That is almost certainly too fast.

    Also, if you want to remove an object from a Collection while you are iterating over it, you need to do this:

    Iterator<T> itr = collection.iterator();
    while(itr.hasNext()) {
        T obj = itr.next();
        if(removeObj) {
            itr.remove();
        }
    }
    

    ConcurrentModificationExceptions lead to non-deterministic behavior. You need to avoid them, not ignore them.

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

Sidebar

Related Questions

I'm in the process of writing a Java 2D game. I'm using the built-in
While writing a game for J2ME we ran into an issue using java.lang.Integer.parseInt() We
I am writing a bouncing ball game in Java for Android phones. Everything seems
I'm writing a Risk-like board game in java. A feature is that players can
I'm writing a MUD (text based game) at the moment using java. One of
I am writing a game using Java Swing. I want to paint each time
I'm writing a game in Java, and I want the user to be able
I am writing a game in Java, and need to have mouse interaction. I
I'm writing a Java game and I want to implement a power meter for
I am writing a card game in java where I need to spread cards

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.