Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package scenes; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * * @author <a href="mailto:martin.drost@student.fontys.nl">Martin Dorst</a> */ public class Background extends ApplicationAdapter { ShapeRenderer sr; List<Debris> debris; public Background() { create(); } @Override public void create() { sr = new ShapeRenderer(); sr.setAutoShapeType(true); debris = new ArrayList<Debris>(); for (int i = 0; i < 50; i++) { debris.add(new Debris(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); } } @Override public void render() { Collections.sort(debris); sr.begin(ShapeType.Filled); int i = 0; for (Debris object : debris) { sr.setColor(object.getColor()); if (object.getType() == 0) sr.rect(object.getPosition().x, object.getPosition().y, object.getRadius(), object.getRadius()); else sr.arc(object.getPosition().x, object.getPosition().y, object.getRadius(), 0, 360); object.update(); if (object.getPosition().y + object.getRadius() < 0) { debris.set(i, new Debris(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); } i++; } sr.end(); } }