Now the answer doesnt have to be centered with the programming language I am using (Java), it is really a general question. I am making a 2d platformer, and am autogenerating a terrain with over 30000 tiles (300×100 map). Now, this is obviously causing so so so much lag and flickering.
The one way I can think of to prevent this is to only move objects on screen, but this is really difficult for me to think it through.
It is a side scroller, the guy moves until he reaches the middle, and when hes in the middle, the platforms begin to move, and that is when it gets SO intensive. It has to do those for loops for a whole 30000 tiles every time the swing timer ticks.
Is anyone willing to enlighten me? Just maybe a nudge in the right direction would be great.
Thank you!
You’ll likely be using some variation on MVC for this, and you’ll have no choice but to move everything in the model — the non-GUI logical representation of your program — that needs moving, but the overhead for this shouldn’t be huge. You’ll only need to move things in the view — the GUI portion of your program — that are within the view’s viewport (on the screen), and this will be a very limited subset of the objects on your map.