Game starts lagging when increasing xoffset and yoffset

Hi I have a java game and when I increase the xoffset and yoffset the fps goes down hugely , in the top left corner(xoffset = 0; y offset = 0;) 450 fps , in the bottom right corner I get 19 fps.
Here is the code for my rendering and my world tick();


public void render() {
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				core.pixmap[x + (y * width)] = image[x + core.xoffset][y
						+ core.yoffset];
			}
		}
	}

This is what draws it to the pixmap;

	public void render() {
		BufferStrategy bs = getBufferStrategy();
		if (bs == null) {
			createBufferStrategy(2);
			return;
		}
		
		screen.clear();
		screen.render();
		Graphics g = bs.getDrawGraphics();
		g.drawImage(pixmapimg, 0, 0, width, height, null);
		
		g.dispose();
		bs.show();

	}

handles the image drawing(in a seperate class)

for (int x = -32 + core.xoffset / 32; x < (core.width + core.xoffset + 100) / 32; x++) {
			
			
			for (int y = -32 + core.yoffset / 32; y < (core.height
					+ core.yoffset + 100) / 32; y++) {
				if (x >= 0 && x < (core.width * 3) / 32 && y >= 0
						&& y < (core.height * 3) / 32) {
					core.screen.draw(x * 32, y * 32, map[x][y].getgraphics());
					map[x][y].tick();
				}
			}
		}

and the world.tick();

And the world.tick??? :slight_smile:

Why offset in an array? Sorry, I don’t know what you’re doing, maybe post your project on github or so?

Ahh i see, Offset in the array is because I use 1 array for the map and 2 arrays for rendering(one of which is the DataBufferInt). So for getting the tile I use the offsets. The tilemap is the ENTIRE map where as the pixmap is all that is visible.

anyone?

For starters
why is your bufferstrategy inside your render loop? its getting destroyed/recreated each one?
Same with graphics?

why not initialize() somewhere else for bufferstrategy and then graphics g.

Then just call screen clear, rende,r dispose, show inside the render loop?

Also you seem to be lacking some code in your snippets. Also for example you say in the top left corner(xoffset = 0; y offset = 0;) 450 fps , in the bottom right corner I get 19 fps.

What is the xoffset == ? when its getting 19?

Ooh didnt notice that hold on , ill get those offsets. Also it only checks it but I will change it around.

The offsets are : x = 1152 : y = 1152 i’d like to note that it doesnt just suddenly go to 19 as the x and y offset increases the fps drops.

private boolean graphicsinitialized = false;
	private Graphics g;
	private BufferStrategy bs;

	public void initrender() {
		bs = getBufferStrategy();
		if (bs == null) {
			createBufferStrategy(2);
			initrender();
			System.out.println("test");
			return;
		}
		
	}

	public void render() {

		if (!graphicsinitialized) {
			initrender();
			graphicsinitialized = true;
		}
		g = bs.getDrawGraphics();
		if (g != null) {
			screen.clear();
			screen.render();
			g.drawImage(pixmapimg, 0, 0, width, height, null);

			g.dispose();
			bs.show();
		}

	}

my updated render code

anything?

are you rendering with the width and height of your map?

I render the area of the screen you currently look at.so as the xoffset increases the position it draws in goes further to the right.
Its the width and height of the frame not the map.

Gah ive located the lag to the world.tick(); in the left corner it simulates 400 tiles in the bottom right it simulates over 2000

Ouch, know where it occured?

im just going to rewrite it I have a much better more efficient method that only adds twice.