Hi, I'm currently working on a 2d platformer engine and I'm trying to make it as optomised as possible. The problem however, is that I can't figure out how to efficiently detect objects in an Arraylist without going through the whole thing like so:
for(int f=0;f<Level.tile.size();f++){ if(Level.tile.get(f).contains(pt1) || Level.tile.get(f).contains(pt2)){ if(Level.tile.get(f).id==1 || Level.tile.get(f).id==2 || Level.tile.get(f).id==3 || Level.tile.get(f).id==10){ tiley=Level.tile.get(f).y; isTouchingFloor=true; return true; } } }
Is it possible to only check the objects that are in between two specific x and y points king of like:
If the object's x and y are greater than the screen's top right corner and less than the screen's bottom right corner, then check the object in relation to the player.