Slow images
in
Programming Questions
•
1 year ago
I have some code that loads a 512 by 512 .png. Each 32 * 32 section of the png is a separate tile and I wrote some code that reads an int 2D array and prints the tile it points to. Here's an example of my code:
- PImage tileSheet;
- void setup ()
- {
- size(512, 512);
- tileSheet = loadImage ("sheet.png");
- }
- void draw ()
- {
- displayTiles();
- }
- void displayTiles ()
- {
- for (int i = 0; i < 16; i++)
- {
- for (int j = 0; j < 16; j++)
- {
- drawTile (i, j * 32, i * 32);
- }
- }
- }
- void drawTile (int tileCode, int xPos, int yPos)
- {
- int tileX = tileCode * 32;
- int tileY = tileCode * 32;
- image(tileSheet.get(tileX, tileY, 32, 32), xPos, yPos);
- }
So basically, I'm drawing 16 rows of tiles with each line drawing a different tile 16 times. However, my program is really slow! What am I doing wrong? (I know this example is full speed, but I'm doing the exact same thing except on a very slightly larger scale and I get half my normal framerate)
1