I have a simple for loop:
package com.reed.sidescroller;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Objects {
private static int[] x = { 0, 103, 206, 309, 412, 515, 618, 721, 824, 927, 1030, 1033,
1036, 1039, 1042 };
public static void grass(SpriteBatch batch) {
for (int i = 0; i < 16; i ++){
batch.draw(Assets.grassAndDirt, x[i] , 0);
}
/*
batch.draw(Assets.grassAndDirt, x[0], 0);
batch.draw(Assets.grassAndDirt, x[1], 0);
batch.draw(Assets.grassAndDirt, x[2], 0);
batch.draw(Assets.grassAndDirt, x[3], 0);
batch.draw(Assets.grassAndDirt, x[4], 0);
batch.draw(Assets.grassAndDirt, x[5], 0);
batch.draw(Assets.grassAndDirt, x[6], 0);
batch.draw(Assets.grassAndDirt, x[7], 0);
*/
}
}
But everytime I try and run it, it gives me this error:
AL lib: MMDevApiMsgProc: Unexpected message: 0 Exception in thread "LWJGL Application" java.lang.ArrayIndexOutOfBoundsException: 15 at com.reed.sidescroller.Objects.grass(Objects.java:10) at com.reed.sidescroller.MainMenuScreen.draw(MainMenuScreen.java:32) at com.reed.sidescroller.MainMenuScreen.render(MainMenuScreen.java:40) at com.badlogic.gdx.Game.render(Game.java:46) at com.reed.sidescroller.SideScroller.render(SideScroller.java:16) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:202) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131) AL lib: ReleaseALC: 1 device not closed
it doesnt seem too helpful to me but at least it tells me the objects class is the error.
The commented out part of the code works fine, but it is a bit long, and I had thought that a for loop could have replaced all of that, but it is not working:(