Hi all!
After reading up on Automatic Images I implemented them in my game (which gave a huge fps boost) and I am now trying to get them to work in my mapeditor which is Swing-based.
I am drawing them in a JPanel but after about 40-50 succesive calls to g.drawImage on my second call to repaint everything just stops running.
If anyone has any idea on what I am doing wrong I have included the code that draws and the part that loads the images. Any general information on anything else that i might be doing wrong is gladly appreciated!
Overriden paint-method in JPanel:
1 2 3 4 5 6 7 8 9 10 11
| Image curimg; for (int i=0;i<noTiles;i++) {
xOffset += 32; if ( (i % columns) == 0) { yOffset+=32; xOffset = 0; } curimg = th.getTile(tilesetName, i); g2.drawImage(curimg,xOffset,yOffset,this); } |
Here is the code to load the images:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| util.log("Processing tiles in " + filename); tkImg = Toolkit.getDefaultToolkit().createImage(filename); MediaTracker tracker = new MediaTracker(win);
tracker.addImage(tkImg,0); try { tracker.waitForAll(); } catch (InterruptedException ex) { }
int i=0; for (int y=0;y<tilesY;y++) { for (int x=0;x<tilesX;x++) { tileArray[i] = gc.createCompatibleImage(32,32, Transparency.BITMASK); Graphics2D big = (Graphics2D)tileArray[i].getGraphics(); big.drawImage(tkImg, -32*x, -32*y, null);
i++; } } |