Hi, just wanted to test performance of drawing a tile as a single image versus cutting the tile from a larger image:
Method 1, single 32*32 image
1 2 3 4 5 6 7 8 9
| for(int i = 0; i < 30; i++) for(int j = 0; j < 20; j++) { g.drawImage(img, i*32, j*32, this); g.setColor(Color.red); g.fillRect(0, 0, 200, 50); g.setColor(Color.green); g.drawString("FPS: " + fps, 20, 20); } |
Method 2: 32*32 fragment of 512*512 image
1 2 3 4 5 6 7 8 9
| for(int i = 0; i < 30; i++) for(int j = 0; j < 20; j++) { g.drawImage(img, i*32, j*32, i*32 + 32, j*32 + 32, 0, 0, 32, 32,this); g.setColor(Color.red); g.fillRect(0, 0, 200, 50); g.setColor(Color.green); g.drawString("FPS: " + fps, 20, 20); } |
Conclusion: NO difference at all, I'm a happy camper:)
btw: I think I remember there is a name for this often used method?