I am having some trouble where I have a huge paint function in java and i run many for loops. The objects that I want to paint are in ArrayList’s so I have to use a for loop to draw them all. Is there any way to make this a lot faster? I have already integrated texture culling meaning that anything that is not needed, is not drawn. But the for loop runs for all objects to: 1. evaluate if the object is actually visible and should be drawn 2. draw the object if it is visible.
Thanks in advance and I hope you can help me 😀
[edit]
This is how i’d use it:
for(int loop = 0; loop < objects.size(); loop++)
{
g2d.drawImage(objects.get(loop).image, objects.get(loop).x, objects.get(loop).y, null)
}
Obviously, i initialise my ArrayList somewhere else:
ArrayList<Block> objects = new ArrayList<Block>();
If the overhead of the
forloop is really the culprit, the you can optimize it a little like this: