Results 1 to 4 of 4
- 07-10-2014, 09:09 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 13
- Rep Power
- 0
What's the best way to paint a tile grid?
Hello everyone.
I have a triple-layered grid system (3 2D byte arrays, e.g byte[][]), and I'm currently drawing it by running through the bytes in the array, grabbing the GridBlock object linked to the ID (the byte in the array), then getting the BufferedImage within that GridBlock object, and using Graphics.drawImage() to draw it in the grid. The issue is that drawing hundreds of BufferedImages can cause some major frame drops. Does anyone know a decent alternative, or an improvement I could make?
Here's the code:
Java Code:g.setColor(Util.transparent); for(int i = scrollX/tileSize; i < (scrollX+Properties.width)/tileSize+1; ++i){ for(int j = scrollY/tileSize; j < (scrollY+Properties.height)/tileSize+1; ++j){ for(int k = 0; k < (renderForeground?3:2); ++k){ byte[][] core = (k == 0 ? scene.getCore() : k == 1 ? grid.getCore() : fore.getCore()); if(i > 0 && i < core[0].length && j > 0 && j < core[1].length){ if(core[i][j]>0&&GridBlock.all[core[i][j]]!=null){ if(GridBlock.all[core[i][j]].getImage()!=null){ g.drawImage(GridBlock.all[core[i][j]].getImage(), i*tileSize-scrollX, j*tileSize-scrollY, this.tileSize, this.tileSize, null); if(k==0){ g.fillRect(i*tileSize-scrollX, j*tileSize-scrollY, this.tileSize, this.tileSize); } } } } } } }
Thanks everyone.
- 07-10-2014, 03:46 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: What's the best way to paint a tile grid?
Have you tried drawing it to another BufferedImage and the drawing the entire image using drawImage? Also, if you would provide a complete, compilable, executable example, (Short, Self Contained, Correct Example) it would be easier for us to see the problem.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 07-11-2014, 01:28 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 13
- Rep Power
- 0
Re: What's the best way to paint a tile grid?
I don't think that would be practical in this case. That would mean moving around 3 huge images, with the added issue that the grids are dynamic, and if these huge images are updated every time the grid is, that would mean constant, big freezes.
My question, essentially, is: How can I mass-draw images or mass paint pixels the most efficiently?
- 07-11-2014, 04:32 PM #4
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: What's the best way to paint a tile grid?
You need to provide the requested Short, Self Contained, Correct Example so we can both visualize and help with the problem. I have done quite a bit of graphics (some of it rather intense) and i never had a performance issue.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
Paint is invalid type for variable paint.
By minibronya in forum New To JavaReplies: 3Last Post: 05-25-2012, 06:52 AM -
Tile Map
By Lundager in forum Java 2DReplies: 5Last Post: 05-19-2012, 09:09 PM -
Open Grid Scheduler/Grid Engine
By java software in forum Java SoftwareReplies: 0Last Post: 03-27-2012, 08:00 PM -
Help tile TimeScrambler game
By DrCooksAlot in forum New To JavaReplies: 8Last Post: 01-25-2012, 04:12 PM
Bookmarks