I'm guessing that those background elements aren't just a bunch of single, independent textures that all get rendered at the same time with a random direction, because that would seem a bit TOO much stuff to render...
They probably are, it's really not all that intensive to render 2D textures. I've seen people render over a few thousand independent entities in Java. What you really want to do is utilize psudo-random numbers.
Simply do something like this below:
NOTE: I do not add a function to destroy old objects, you will need to do this if you want to reduce lag over its lifespan.
ALSO NOTE: This is using Java2D, which comparatively to OpenGL is much slower. So, even using a less optimized way to draw things you still don't really see any lag.
Here is a link to the executable jar using the code below. Example.jar
'Falling Object' class.
import java.awt.*;
/**
* Created by Brendyn Todd on 1/14/2016.
*/
public class FallingObject {
public int x,y;
public FallingObject(int x){
this.x=x;
}
public void render(Graphics g, double delta){
//Draw the square down by 2 every step.
y += 2;
//Render a white square on the screen.
g.setColor(Color.white);
g.drawRect(x,y, 25, 25);
}
}
'Main' class
import com.framework.framework.Framework;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
import com.framework.display.Window;
/**
* Created by Brendyn Todd on 1/14/2016.
*/
public class Main extends Framework {
ArrayList<FallingObject> objects = new ArrayList<FallingObject>();
double time, lastTime = 15;
public Main(){
//Do not mind these boilerplate lines of code. They are from my own personal Framework.
register(new Window("Example", 480, 320), null);
start();
}
public void update(Graphics g, double delta) {
//Set the background color.
g.setColor(Color.black);
//Draw the black background to our window size. 480w x 320h
g.fillRect(0,0,480,320);
//Allows us to control time. Woooooo.
time += delta;
//Checks if enough time has passed.
if(time > lastTime){
addObject();
//Update the last time we created a new object.
lastTime = time + 15;
}
//Loop through and render the objects.
for(int i = 0; i < objects.size(); i++){
FallingObject fo = objects.get(i);
fo.render(g,delta);
}
}
public void addObject(){
/Initialize the Random class.
Random random = new Random();
//Set the objects X Position to a random location within the windows width.
int xPos = random.nextInt(480);
//Add it to the array list to render it, also setting its random xPosition.
objects.add(new FallingObject(xPos));
}
//BEGIN!
public static void main(String[] args){
new Main();
}
}