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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:00:48+00:00 2026-06-11T19:00:48+00:00

What i´m trying to do here is rendering all graphics in my game as

  • 0

What i´m trying to do here is rendering all graphics in my game as fast as possible.
The game is tile-based and needs a lot of images to be rendered.
The problem i´m having is that it takes to long to draw all the images.
I don´t know if i´m supposed to draw the tiles in a special way but right now i´m rendering all tiles that are inside of the view port one by one.

Here is my drawing method:

public void draw(Graphics2D g){

    boolean drawn=false; // if player is drawn
    int px=vpPosX, py=vpPosY; // Viewport Position

    for(int y=Math.round(py/64); y<Math.round(py/64)+core.blcHeight; y++){
        for(int x=Math.round(px/64); x<Math.round(px/64)+core.blcWidth; x++){
            if(y<height && x<width && y>-1 && x>-1 && worldData[currentLayer][x][y] != 0){ // if tile is inside map
            BufferedImage img = tileset.tiles[worldData[currentLayer][x][y]]; //tile image
            if(-py+player.PosY+64-15 < (y*64)-py-(img.getHeight())+64 && drawn==false){player.draw(g);drawn=true;} // if player should be drawn
                if(worldBackground[currentLayer][x][y]!=0){ // if tile has background
                    BufferedImage imgBack = tileset.tiles[worldBackground[currentLayer][x][y]]; // background tile
                    g.drawImage(imgBack, (x*64)-px-(((imgBack.getWidth())-64)/2), (y*64)-py-(imgBack.getHeight())+64, null); //draw background
                }
                g.drawImage(img, (x*64)-px-(((img.getWidth())-64)/2), (y*64)-py-(img.getHeight())+64, null); // draw tile
            }
        }
    }

    if(!drawn){player.draw(g);} // if drawn equals false draw player

    }

All of the images are loaded in the tileset class.
The games fps/ups is locked at 60.
This method is called from the core class which has the gameloop.

The thing i want to know is what am i doing wrong?
Do i need to change the draw method?
Do i need to load the images in a special way?
Do i need to change the way i´m painting?

My goal is to make a lag free 2d tile game.

The things i noticed myself was that my bufferedimages that hold the tile images was in RGBA format. But when i made it RGB it took a lot less time to render. I know the extra info is taking more time to draw. But what i didn’t know was how much it really was.

I managed to find one thing that made the performance better.
If i loaded all my images and copied them over to a image created in this way:

BufferedImage bi = ImageIO.read(ims[i]);
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage b = gc.createCompatibleImage(bi.getWidth()*4, bi.getHeight()*4, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = b.createGraphics();
g.drawImage(bi, 0, 0, bi.getWidth()*4, bi.getHeight()*4, null);
tiles[id]=b;
g.dispose();

Then the it took a lot less time to draw all the tiles.
But it could still be better.
And when i´m going to make the light engine(for example underground).
Then i would have to use transparent rectangles over the tiles.
Or if someone could suggest a better way of making tiles darker without using transparent rectangles. But the thing is that the lag comes when trying to draw transparent rectangles too. I don´t know if i´m supposed to avoid using transparent images and rectangles or what.

Hope someone can point me in the right direction.

  • 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-11T19:00:50+00:00Added an answer on June 11, 2026 at 7:00 pm

    Some tricks you might find helpful:

    • If you have lot of static background tiles, then don’t redraw them all every frame – just draw them once into a BufferedImage and use this to draw the entire background in one go. You only need to update this background image if one of the tiles changes or if you scroll the screen etc.
    • Make sure you are only drawing tiles that are visible. It looks like you might be doing this, but if core.blcHeight and core.blcWidth are too large then you could be drawing too many tiles.
    • Don’t worry about locking to 60FPs. For a tile based game, this probably isn’t going to be necessary. I’d suggest decoupling your game logic from the frame rate, and letting the game render at whatever speed it can handle.
    • For solid background tiles, you don’t need to be drawing with alpha shading. This can significantly speed up drawing in some cases. i.e. you can use TYPE_INT_RGB rather than TYPE_INT_ARGB

    If you really want high performance drawing/animation then you may want to consider switching to an OpenGL-based rendering engine – Slick2D or LWJGL for example.

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

Sidebar

Related Questions

I have a problem here im trying to upload a file first time it
I'm trying to create a Tile rendering program. Heres some basic code. Header class
I'm trying to show 1000 quite small images on a page (rather a lot
Beginner here trying to get a pipeline working in bash. If somebody can see
I am going nuts here trying to resolve a cascading update/delete issue :-) I
I'm pulling my hair out here trying to get CSS to position only a
I know of the ||= operator, but don't think it'll help me here...trying to
What I am trying to accomplish here is to separate a firstname, lastname combo
What I am trying to do here is: IF the records in table todo
I have a bunch of divs I'm trying to organize here. The ones I'm

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.